One of my scripts “Sprint” is disabled until the server finds the data in datastore. The issue is that it of course only does this when the player has joined the game. So when the humanoid dies, the Sprint script is disabled again, but not enabled.
I tried to write a script below, but it doesn’t work. I think it’s because the script itself is removed and readded to the player when Health > 0, so the script just goes back to the first line and doesn’t trigger what comes after the while loop
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
Humanoid.Died:Connect(function()
while Humanoid.Health == 0 do
task.wait()
end
game.Players.LocalPlayer.Character.Sprint.Enabled = true
print(game.Players.LocalPlayer.Character.Sprint.Enabled)
end)
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
Humanoid.Died:Connect(function()
while Humanoid.Health == 0 do
task.wait()
end
game.Players.LocalPlayer.Character.Sprint.Disabled= false
print(game.Players.LocalPlayer.Character.Sprint.Disabled)
end)
Try to activate it in server. You can make another Remote and do this:
Client
local Humanoid = game.Players.LocalPlayer.Character.Humanoid
Humanoid.Died:Connect(function()
while Humanoid.Health == 0 do
task.wait()
end
remoteEvent:FireServer(game.Players.LocalPlayer.Character.Sprint)
print(game.Players.LocalPlayer.Character.Sprint.Disabled)
end)
The Sprint script is local so enabling it on the server wouldn’t work in the first place,
but like I said in my post: The script can’t go to code past the while do loop. Local/Server has nothing to do with anything if everything is done locally, no?
Are you putting that script in StarterCharacterScripts? You should put the script in StarterPlayerScripts instead, where it doesn’t get re-added every time.
Because at the time, the character has not loaded yet. So the script finds it as nil.
Player has an event called Player.CharacterAdded(), which fires whenever the character spawns. You should modify your script a bit with it.
Input: local Humanoid = game.Players.LocalPlayer.CharacterAdded().Humanoid
Output: Players.youbigown.PlayerScripts.diedSprintEnable:2: attempt to call a RBXScriptSignal value
no. It’s like this: The humanoid dies from the player resetting or getting killed by something.
Then the event is triggered and the function is run. Inside the function is a loop that waits for the player to be revived theoretically. The problem is that in practice the loop does run, but when it’s done (humanoid has been revived) the script just ignores everything after the while loop. In this case it ignores game.Players.LocalPlayer.Character.Sprint.Enabled = true print(game.Players.LocalPlayer.Character.Sprint.Enabled)
Anything after the while loop won’t be run, so the print can’t be there.
I put it here
Humanoid.Died:Connect(function()
print(Humanoid.Health)
print(game.Players.LocalPlayer.Character.Sprint)
while Humanoid.Health == 0 do
task.wait()
end
game.Players.LocalPlayer.Character.Sprint.Enabled = true
print(game.Players.LocalPlayer.Character.Sprint.Enabled)
end)
Set the Health of the humanoid to something more than zero on the server, see if the Script enables.
Maybe the reason why it doesn’t work is because it never changed the health so it will continue yielding waiting for something that will never happen.-