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

This script doesn't work after a player dies, what do I do?

Hey, I'm developing a training facility, and I made a script that gives you tools/GUIs if you are in a team (for example, if you are in the Red Team you get a pistol, etc..) It works when a player joins, but it doesn't work after the player dies. I want the script to work after a player dies. Note: This is a LocalScript

local code = require(game.ReplicatedStorage:WaitForChild("TeamAssets").Settings)
local plr = game.Players.LocalPlayer
local char = plr.Character
assets = game.ReplicatedStorage:FindFirstChild("TeamAssets")
function giveitem(asset,location)
    if assets:findFirstChild(asset) == nil then print('Error - could not find asset '..asset) return end
    if plr:findFirstChild(location) == nil then print('Error - could not find player child '..location) return end
    --local newasset = assets[asset]:Clone()
    --newasset.Parent = plr[location]
	if location=="Backpack" then
		workspace.Remotes.Equipper:FireServer(asset,nil,true,code.code)
	end
	if location=="PlayerGui" then
		assets:FindFirstChild(asset):Clone().Parent=plr.PlayerGui
	end
end
if plr.TeamColor == BrickColor.new 'White' then
	giveitem('ArmorBlue','PlayerGui')
	giveitem('Detain','Backpack')
end
if plr.TeamColor == BrickColor.new 'Really red' then
	giveitem('ArmorRed','PlayerGui')
end

I'll really appreciate it if someone helps me with this.

1 comment

0

What folder is the script in?

1 answer

Simply use CharacterAdded event, so when the player respawns it adds the tools into the player.

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		--  Run your code and when you set your parent do .Parent = char
	end)
end)

1 comment

0

I've attempted this, but it still did not work.

This discussion is preserved as it was. New answers, comments, and votes are closed.