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

How do you make a tool respawn after it gets deleted/a player dies while holding it?

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?

2 comments

0

I don't quite understand what you mean. Are you trying to make the tools stay in the players inventory when they die?

0

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.

1 answer

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.