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

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

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

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)

2 comments

0

How do i "add" inside?

0

What i mean is "how?" like, add it on the end of the script or top?

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