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

Help with the script?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

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

Log in to vote
2
Answered by 9 years ago

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.

Ad

Answer this question