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

Help with the script?

I alredy know how to give an item to a player when he joins by having his name, the question is how to give it after he respawns too.

Player = game.Players.LocalPlayer
	if Player.Name == "Player" then
		local emi = game.Lighting:WaitForChild("Emi")
		emi:Clone().Parent = Player:WaitForChild("Backpack")
	end

^That's not working.

1 answer

✓ Accepted answer

There is something called StarterGear. When a player respawns it will give the gear to the player that has the gear in StarterGear.

Player = game.Players.LocalPlayer
    if Player.Name == "Player" then
        local emi = game.Lighting:WaitForChild("Emi")
        emi:Clone().Parent = Player:WaitForChild("Backpack")
	emi:Clone().Parent = Player:WaitForChild("StarterGear")
    end

You should also add this debounce type thing so it doesn't flood your inventory with gear when you respawn.

Player = game.Players.LocalPlayer
    if Player.Name == "Player" and not Player:WaitForChild("StarterGear").Emi then
        local emi = game.Lighting:WaitForChild("Emi")
        emi:Clone().Parent = Player:WaitForChild("Backpack")
	emi:Clone().Parent = Player:WaitForChild("StarterGear")
    end

Another thing.

This works perfectly fine. As long as it's a local script.

Player = game.Players.LocalPlayer
    if Player.Name == "Player" then
        local emi = game.Lighting:WaitForChild("Emi")
        emi:Clone().Parent = Player:WaitForChild("Backpack")
    end
--Your Original script works in a local script.

This needs to be a local script since you use LocalPlayer which can only be accessed through LocalScripts.


If this is a regular script, use this code:

game.Players.PlayerAdded:connect(Player)
    if Player.Name == "Player" then
        local emi = game.Lighting:WaitForChild("Emi")
        emi:Clone().Parent = Player:WaitForChild("Backpack")
    end
end) --Regular script.

Also, if this doesn't work in studio it's probably because your name is "Player1" not "Player". If you want to do multiple people then use this script. This uses pairs and tables/arrays.

PeopleWhoCanGetGear = {"Player", "Player1", "Someone else."} --Add Names here.

game.Players.PlayerAdded:connect(function(Player)
       for _,names in pairs(PeopleWhoCanGetGear) do
		if Player.Name == names then
       			local emi = game.Lighting:WaitForChild("Emi")
        		emi:Clone().Parent = Player:WaitForChild("Backpack")
				emi:Clone().Parent = Player:WaitForChild("StarterGear")
		end
	end
end) --Regular Script

Local:

PeopleWhoCanGetGear = {"Player", "Player1", "Someone else."} --Add Names here.

Player = game.Players.LocalPlayer
       for _,names in pairs(PeopleWhoCanGetGear) do
		if Player.Name == names then
       			local emi = game.Lighting:WaitForChild("Emi")
        		emi:Clone().Parent = Player:WaitForChild("Backpack")
		end
	end --Local Script


Also LocalScripts must be in a child of Player. So put them in StarterGui or startergear. If it's a regular script just leave it in Workspace.

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