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

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

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

✓ Accepted answer

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)

2 comments

0

how would i fix this then?

0

Ive edited my response with a possible fix

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