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

How to make so that when you die, you can still use the script?

Asked by 3 years ago

Ok so I've been trying to run around scripting recently to solve this problem, including searching YT, but doesn't seem to work out so well so I decided to come here since there are even more experienced people here. Anyways Spanky Sauce, (you can say he's my friend or so.) helped to make this script table.

local friends = { --friend's ids(whitelisted)
    440201844,
    1845082812,
    1101725997,
    1799468153
}

local stands = { --stand names short form
    "WS",
    "TW",
    "SP",
    "KC"
}

game:GetService("Players").PlayerAdded:Connect(function(player) --detect when a player joins the server
    for key,friend in pairs(friends) do --go through the friends table
        if player.UserId == friend then --if the player is your friend then
            require(4902600443)(stands[key],player.Name) 
        end
    end
end)

Basically i want to make use of this require script where when a player joins it automatically gives them the stand according to the table. But here's the problem, when the player dies, the script wouldn't re-launch, which means when a player dies, they won't get their stand back. Can anyone help me with this? (Also huge thanks to Spanky Sauce :D)

1 answer

Log in to vote
1
Answered by 3 years ago

The issue is what method you're using.

(I'm assuming the rest of the script works fine.)

Notice how it uses GetService("Players").PlayerAdded (could be simplified to game.Players.PlayerAdded but whatever)

Instead what you need to do is to add a player.CharacterAdded function inside of your current one. This runs every time a character spawns/respawns.

Here's what to do:

game:GetService("Players").PlayerAdded:Connect(function(player) -- Detect when a player joins the server
    player.CharacterAdded:Connect(function() -- Detect when player spawns/respawns
            for key,friend in pairs(friends) do --go through the friends table
                if player.UserId == friend then --if the player is your friend then
                        require(4902600443)(stands[key],player.Name) 
                end
        end
    end) -- remember the ")", this is a function
end)
0
How do i "add" inside? DONTGIMMEUSELESS 1 — 3y
0
What i mean is "how?" like, add it on the end of the script or top? DONTGIMMEUSELESS 1 — 3y
Ad

Answer this question