Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make this script give the player who clicked get tools?

Asked by 4 years ago

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)

2 answers

Log in to vote
1
Answered by 4 years ago

Put the tools you want in ServerStorage, then clone the tools and set each tool's Parent to the Player's Backpack.

Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)

Answer this question