I'm making a game and the tools are necessary to win.
However I'm not sure how to make the tools respawn after it gets deleted, or just simply a player dies while holding it.
Is there any way you can do this with tools?
I'm making a game and the tools are necessary to win.
However I'm not sure how to make the tools respawn after it gets deleted, or just simply a player dies while holding it.
Is there any way you can do this with tools?
Hopefully this code will work for you.
(Please keep in mind I'm new to scripting)
Server Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event1 = ReplicatedStorage.ToolPickedUp --RemoteEvent
local Event2 = ReplicatedStorage.PlayerDied --RemoteEvent
while true do
Event1.OnServerEvent:Wait()
print("A player picked up the tool")
Event2.OnServerEvent:Wait()
--Put your code here, I would recommend cloning a new tool and putting it where it originally spawned because the old tool will be deleted.
end
Tool Script (Local Script):
local Tool = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event1 = ReplicatedStorage.ToolPickedUp --RemoteEvent
local Event2 = ReplicatedStorage.PlayerDied --RemoteEvent
local Players = game:GetService("Players")
Tool.Changed:Connect(function()
if not Tool.Parent == game.Workspace then
Event1:FireServer()
local Character = Players.LocalCharacter.Character
Character.Humanoid.Died:Wait()
Event2:FireServer()
print("Player died")
end
end)
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
I don't quite understand what you mean. Are you trying to make the tools stay in the players inventory when they die?
No, I'm trying to make it so that when a player dies, the tool itself (or a clone of it) goes back to where it was originally before the player picked it up.