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

How to make an ImageLabel move every time the player character dies?

Asked by 7 years ago

Trying to make an imagelabel move every time the player character dies.

But the script only does its job on one death.

Help?

local n = script.Parent
player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:wait()
humanoid = player.Character:WaitForChild("Humanoid")

humanoid.Died:connect(function ()
    wait(5)
    n.Position = n.Position - UDim2.new(0,-30,0,0)

end)
0
Did u put it in starter character scripts? GForcebot 0 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Here is why: This is a GUI, and the script is a local script inside of it, correct? When the character dies, it will wait 5 seconds. In about 4 seconds, the character would respawn. Then, the next second, the Gui is moved. Seems like it would work, but the Gui would reset it's position when the player respawns. So therefore, it would seem like the function is only running once. You can stop this in several ways: Have a count IntValue somewhere in the player, that tells you how many times he has died or so, and adjust the position of the TextLabel accordingly. Example:

local n = script.Parent
player = game.Players.LocalPlayer
character = player.Character or player.CharacterAdded:wait()
humanoid = player.Character:WaitForChild("Humanoid")
local Times = player.Times -- Make the IntValue through another script
humanoid.Died:connect(function ()
    wait(5)
    Times.Value = Times.Value + 1-- Don't worry about this affecting FE, unless the position of your textlabel is crucial to the game and someone has a reason to exploit it.
    n.Position = n.Position - UDim2.new(0,-30*Times.Value,0,0)
end)

Of course, that is only one way. You don't even have to follow it the same way, but the point is to have a count of how many times the player dies. The second way would be to adjust the Gui's settings so that it does not respawn, if it's an option. You can also keep track of where the position was prior to the respawn, and adjust that. Anyways, it shouldn't be difficult and if it turns out to be, feel free to post a question. Just think of the right way for your game

0
I was able to get the script to work in my game, but the same result happens. IT only does its job once, help? JoeRaptor 72 — 7y
0
Put a print in there and tell me if it only prints it once or multiple times iamnoamesa 674 — 7y
Ad

Answer this question