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 4 years ago
Edited 4 years ago
local main = script.Parent
local walkbtn = main.EnterTextBtn
local jumpbtn = main.EnterTextBtn2
local player = game.Players.LocalPlayer 
local Character = player.Character or player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid") 
local amount = main.Amount

walkbtn.MouseButton1Down:connect(function() 
humanoid.WalkSpeed = amount.Text
end)

jumpbtn.MouseButton1Down:connect(function() 
humanoid.JumpPower = amount.Text
end)

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 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

local main = script.Parent
local walkbtn = main.EnterTextBtn
local jumpbtn = main.EnterTextBtn2
local player = game.Players.LocalPlayer 
local amount = main.Amount

walkbtn.MouseButton1Down:connect(function()
    if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
        player.Character:FindFirstChildOfClass("Humanoid").WalkSpeed = tonumber(amount.Text)
    end
end)

jumpbtn.MouseButton1Down:connect(function()
    if player.Character and player.Character:FindFirstChildOfClass("Humanoid") then
        player.Character:FindFirstChildOfClass("Humanoid").JumpPower = tonumber(amount.Text)
    end
end)
0
how would i fix this then? Scorched_Liam 19 — 4y
0
Ive edited my response with a possible fix thatwalmartman 404 — 4y
Ad

Answer this question