Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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.

0
What folder is the script in? Cousin_Potato 129 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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)
0
I've attempted this, but it still did not work. Mark512345 2 — 5y
Ad

Answer this question