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

if a character dies my script does not work please help?

Asked by 5 years ago
Edited 5 years ago
01local main = script.Parent
02local walkbtn = main.EnterTextBtn
03local jumpbtn = main.EnterTextBtn2
04local player = game.Players.LocalPlayer
05local Character = player.Character or player.CharacterAdded:Wait()
06local humanoid = Character:WaitForChild("Humanoid")
07local amount = main.Amount
08 
09walkbtn.MouseButton1Down:connect(function()
10humanoid.WalkSpeed = amount.Text
11end)
12 
13jumpbtn.MouseButton1Down:connect(function()
14humanoid.JumpPower = amount.Text
15end)

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

I can't say for sure because PlayerGui should be reset on death anyways but I am assuming that it is erroring because you are declaring the humanoid variable one time. After the player dies, their character is deleted and respawned which means that the humanoid value is now nil

01local main = script.Parent
02local walkbtn = main.EnterTextBtn
03local jumpbtn = main.EnterTextBtn2
04local player = game.Players.LocalPlayer
05local amount = main.Amount
06 
07walkbtn.MouseButton1Down:connect(function()
08    if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
09        player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = tonumber(amount.Text)
10    end
11end)
12 
13jumpbtn.MouseButton1Down:connect(function()
14    if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
15        player.Character:FindFirstChildOfClass("Humanoid").JumpPower = tonumber(amount.Text)
16    end
17end)
0
how would i fix this then? Scorched_Liam 19 — 5y
0
Ive edited my response with a possible fix thatwalmartman 404 — 5y
Ad

Answer this question