Hello. I have a tool that can be equipped if a player clicks on it and it will move to game.Lighting. Now I want the tool to respawn on the map if the player dies. Here’s my scirpt.
local tool = game.ReplicatedStorage["Blue Flag"]
local flag = script.Parent
local click = script.Parent.ClickDetector
local function pickup(player)
local Player = game.Workspace[player.Name]
tool.Parent = Player
flag.Parent = game.Lighting
if Player.Humanoid.Died then
flag.Parent = game.Workspace
end
end
click.MouseClick:Connect(pickup)
Thanks in advance
2 Likes
Why you move it to game.Lighting? Try to move it into game.ServerStorage
1 Like
You have some issues with your code
-
It’s only going to give the tool once regardless, you don’t clone the tool, you just parent the one in Replicated
-
Died is not a property, it’s an event.
-
The way you get the character is weird, if you got the player instance, just use player.Character
-
A bit of a preference but Lighting as a storage place is kinda old and you should use somewhere such as ServerStorage
-
If someone is dead and clicks on the flag, they will pick it up regardless and the event wont happen, you should probably have a check that only allows them to pick it up if their health is greater than 0
local tool = game.ReplicatedStorage["Blue Flag"]
local flag = script.Parent
local click = script.Parent.ClickDetector
local function pickup(player)
local character = player.Character
if character.Humanoid.Health <= 0 then
return
end
tool:Clone().Parent = character
flag.Parent = game:GetService("ServerStorage")
character.Humanoid.Died:Connect(function()
flag.Parent = workspace
end)
end
click.MouseClick:Connect(pickup)
3 Likes