Door = script.Parent cooldown = 5 --How much time in seconds it takes for the door to open again. change if you wish. value = false function OnClicked() if (value == false) then value = true end local cloned = game.Lighting.Water:Clone() game.Lighting.Water:Clone().Parent = game.Players.LocalPlayer.Backpack Door.ClickDetector.MaxActivationDistance = 0 wait(cooldown) value = false Door.ClickDetector.MaxActivationDistance = 10 end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
I try clicking on Door to get the 'Water' gear but it says LocalPlayer is a nil value. How can I tell it to give the gear to whoever is clicking?
It works in the studio, but not in the real game.
Door = script.Parent cooldown = 5 --How much time in seconds it takes for the door to open again. change if you wish. value = false function OnClicked(player) if (value == false) then value = true end local cloned = game.Lighting.Water:Clone() game.Lighting.Water:Clone().Parent = player cloned.Handle.Anchored = false cloned.Handle.Locked = false Door.CanCollide = false Door.ClickDetector.MaxActivationDistance = 0 wait(cooldown) value = false Door.ClickDetector.MaxActivationDistance = 10 end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
Door = script.Parent cooldown = 5 --How much time in seconds it takes for the door to open again. change if you wish. value = false function OnClicked(player) if (value == false) then value = true end local cloned = game.Lighting.Water:Clone() game.Lighting.Water:Clone().Parent = player.Backpack -- Notice this cloned.Handle.Anchored = false cloned.Handle.Locked = false Door.CanCollide = false Door.ClickDetector.MaxActivationDistance = 0 wait(cooldown) value = false Door.ClickDetector.MaxActivationDistance = 10 end script.Parent.ClickDetector.MouseClick:connect(OnClicked)
You were parenting your tool to the player itself rather than the player's Backpack. Hopefully your script works now.
Best regards!