The code should now look like this: local Part = script.Parent-Defines the part I am going to copy the code to each of my numbers that I have in my events. Make sure to change UI1 to a different var when you call a different UI. The UI1 can be changed, but I’ll just have it as UI1 for now. UI1.Enabled = false -Make sure the "UI" part is the same is the one above or the UI will stay there forever Next lets make it so when the number is called the UI become visible: if randomNum = 1 then-If math.random is equal to 1 then fire fire the event Local UI2 = gui:FindFirstChild("Shotgun") Your code should look somewhat like this: local Part = script.Parent-Defines the part I will add 3 more UI’s so each number has a different UI when it is called. My UI’s name is AK-47, if your UI’s name was “e” then it would be gui:FindFirstChild("e"). This just defines the UI and what the UI name is, you should change it to whatever your ScreenUI name is for example: The code should be right under the MouseClicked function. Local UI1 = gui:FindFirstChild("AK-47")-Change this to whatever your UI name is Next lets make it so when a certain number is reached a certain UI shows up: local gui = Player.PlayerGui If you test the game it should look like this: If randomNum = 4 then-If math.random is equal to 4 then fire fire the event If randomNum = 3 then-If math.random is equal to 3 then fire fire the event If randomNum = 2 then-If math.random is equal to 2 then fire fire the event If randomNum = 1 then-If math.random is equal to 1 then fire fire the event This code makes it so when the var randomNum is equal to 1 it prints out “math.random = 1”, you should copy this to tell all numbers print out something when they are chosen.Ĭurrently your code should be somewhat similar to this: local Part = script.Parent-Defines the partĬD.MouseClick:Connect(function(Player) -Find out when the player clicks the chest Now that we have our base functions made, lets make it so when math.random() is a certain number it fires an event: if randomNum = 1 then-If math.random is equal to 1 then fire fire the event When you run it, it should look like this: We have just made the first part of our script! The part var and CD var define the click detector and the script’s parent, the function finds out when it’s been clicked and the randomNum var picks a random number from 1 to 4 and then prints it. You can name randomNum to whatever you want, but you will need to change the code to match your var name. Local randomNum = math.random(1,4)-Choose a random number from 1 to 4 The print function isn’t needed but is good to have for debugging purposes.įinally, lets add our math.random() variable: CD.MouseClick:Connect(function(Player) -Find out when the player clicks the chest This event fires when the parent is clicked, and when the event fires all the code inside of it runs. Next lets make our function that fires when the part is clicked: CD.MouseClick:Connect(function(Player) -Find out when the player clicks the chest The part var defines the parent so we know what the parent is, then the CD var searches through the parent to find the click detector. Local CD = Part.ClickDetector-Defines the click detector. Now, inside of the script you have to add this variable into the script: local Part = script.Parent-Defines the part You can name the script whatever you want, we won’t need to call the script name in order to give a player an item. Now that we have our chest in our game, we will make the base functions of our script.įirst lets insert a script into our chest: Once your finished we will move onto scripting the base of our chest! It shouldn’t take to long to setup your chest and add the click detector inside of it. We will use our click detector to find out when a user has clicked our chest, so we know when to give them an item. Next lets add a click detector into our chest model: If you do grab a free model chest make sure you remove all scripts from it. This is a chest model I found in the toolbox.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |