Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.