Hii! I have this script, it works but when someone clicks the part, it gave everyone the tool and not to the only one that clicked on it.
toolname = "Purple- White Ribbon" --Change Whatever to the name of the tool that is in Lighting
epic = true
game.Players.PlayerAdded:connect(function(newPlayer)
newPlayer.CharacterAdded:connect(function(char)
script.Parent.ClickDetector.MouseClick:connect(function()
if epic == false then return end
wait()
epic = false
tool = game.Lighting:findFirstChild(toolname):clone()
tool.Parent = game.Players:findFirstChild(char.Name).Backpack
wait()
epic = true
end)
end)
end)
You can condense your code this way, avoid connecting unnecessary function, because the ClickDetector.MouseClick apparently returns a player.
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if not epic then return end
wait()
epic = false
tool = game.Lighting:FindFirstChild(toolname):Clone() -- don't use game.Lighting as storage, use ServerStorage or ReplicatedStorage
tool.Parent = player.Backpack
wait()
epic = true
end)
toolname = "Purple- White Ribbon" --Change Whatever to the name of the tool that is in Lighting
epic = true
game.Players.PlayerAdded:connect(function(newPlayer)
newPlayer.CharacterAdded:connect(function(char)
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if not epic then return end
wait()
epic = false
tool = game.SeverStorage:FindFirstChild(toolname):Clone() -- don't use game.Lighting as storage, use ServerStorage or ReplicatedStorage
tool.Parent = player.Backpack
wait()
epic = true
end)
No. It should look like this. However, you should move the tool into ReplicatedStorage or ServerStorage. This script is for ReplicatedStorage.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = ReplicatedStorage:FindFirstChild("Purple- White Ribbon")
local epic = true
script.Parent.ClickDetector.MouseClick:Connect(function(player)
if not epic then
return
end
epic = false
clonedTool = Tool:Clone()
clonedTool.Parent = player.Backpack
wait()
epic = true
end)