Hello people, I am making a chest script and I need to make it give tools to whoever clicked after the chest animation is done. Here is the script:
---Variables--- local clickdetector = script.Parent:WaitForChild("ClickDetector") Phase0 = script.Parent.Parent.Phase0 Phase1 = script.Parent.Parent.Phase1 Phase2 = script.Parent.Parent.Phase2 Phase3 = script.Parent.Parent.Phase3 Phase4 = script.Parent.Parent.Phase4 Phase5 = script.Parent.Parent.Phase5 ---------------------------------------------------------------- ---Animate--- clickdetector.MouseClick:Connect(function() Phase0.Transparency = 1 Phase1.Transparency = 0 wait(0.1) Phase1.Transparency = 1 Phase2.Transparency = 0 wait(0.1) Phase2.Transparency = 1 Phase3.Transparency = 0 wait(0.1) Phase3.Transparency = 1 Phase4.Transparency = 0 wait(0.1) Phase4.Transparency = 1 Phase5.Transparency = 0 script.Parent.ParticleEmitter.Enabled = false wait(0.5) --Where I want it to give tools-- end)
Put the tools you want in ServerStorage, then clone the tools and set each tool's Parent to the Player's Backpack.
As Crvnberie said, you can clone the items into ReplicatedStorage or ServerStorage and then put it in their backpack.
The ClickDetector.MouseClick
event returns the player who clicked so you can access it in your code.
---Variables--- local clickdetector = script.Parent:WaitForChild("ClickDetector") Phase0 = script.Parent.Parent.Phase0 Phase1 = script.Parent.Parent.Phase1 Phase2 = script.Parent.Parent.Phase2 Phase3 = script.Parent.Parent.Phase3 Phase4 = script.Parent.Parent.Phase4 Phase5 = script.Parent.Parent.Phase5 ---------------------------------------------------------------- ---Animate--- clickdetector.MouseClick:Connect(function(player) -- This event returns the player who clicked Phase0.Transparency = 1 Phase1.Transparency = 0 wait(0.1) Phase1.Transparency = 1 Phase2.Transparency = 0 wait(0.1) Phase2.Transparency = 1 Phase3.Transparency = 0 wait(0.1) Phase3.Transparency = 1 Phase4.Transparency = 0 wait(0.1) Phase4.Transparency = 1 Phase5.Transparency = 0 script.Parent.ParticleEmitter.Enabled = false wait(0.5) --Where I want it to give tools-- -- EXAMPLE -- tool.Parent = player.Backpack -- you can write something like this end)