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

Why does everything work in my script except the walkspeed changer?

Asked by 2 years ago

Heres the code:

script.Parent.MouseEnter:Connect(function()
    script.Parent.continue_Roundify_12px.ImageColor3 = Color3.new(1, 0.839216, 0.243137)
end)
script.Parent.MouseLeave:Connect(function()
    script.Parent.continue_Roundify_12px.ImageColor3 = Color3.new(0.278431, 1, 0.447059)
end)
script.Parent.MouseButton1Click:Connect(function()
    wait(1)
    script.Parent.Parent.Parent.Parent.Customization:Destroy()
    local Camera = workspace.CurrentCamera
    Camera.CameraType = Enum.CameraType.Custom
    workspace.idkman:Destroy()
    local h = script.Parent.Parent.Parent.Parent.Parent.Character.Humanoid
    h.WalkSpeed = 16
end)

Why is it that the walkspeed code doesn't work? Here's the error I get back when I tried to test it in game: "Players.watsup1087.PlayerGui.Customization.mainframe2.continue.LocalScript:13: attempt to index nil with 'Parent' " I have tried many fixes but none seem to work. Any help would be much appreciated!

2 answers

Log in to vote
3
Answered by
VitroxVox 884 Moderation Voter
2 years ago
Edited 2 years ago

Hello! So I've looked at your script and I'm not sure why you're trying to find the player via the script's parent's.

As it's a localscript you can get the player easily by using roblox's player service or "game.Players".

Here's the fix:

script.Parent.MouseEnter:Connect(function()
    script.Parent.continue_Roundify_12px.ImageColor3 = Color3.new(1, 0.839216, 0.243137)
end)
script.Parent.MouseLeave:Connect(function()
    script.Parent.continue_Roundify_12px.ImageColor3 = Color3.new(0.278431, 1, 0.447059)
end)
script.Parent.MouseButton1Click:Connect(function()
    wait(1)
    script.Parent.Parent.Parent.Parent.Customization:Destroy()
    local Camera = workspace.CurrentCamera
    Camera.CameraType = Enum.CameraType.Custom
    workspace.idkman:Destroy()
    local player = game:GetService("Players").LocalPlayer
    local h = player.Character.Humanoid or workspace:FindFirstChild(player).Humanoid
    h.WalkSpeed = 16
end)
0
Thank you! I wish I had known this beforehand, the parent thing was a very stupid idea too be honest. CameUpFromNothing 37 — 2y
Ad
Log in to vote
-2
Answered by 2 years ago
Edited 2 years ago

Here Is a part that speeds you when you touch It:

script.Parent.Touched:Connect(function(hit) --- this will cause the event to happen
    local plr = game.Players:GetPlayerFromCharacter(hit.Parent) ---- This will describe the humanoid


    if plr then --- If Its a player then
        hit.Parent.Humanoid.WalkSpeed = 100 --- sets the walkspeed to 100
    end
end)
-1
No.. this isn't even near what he asked you just copy & pasted a template. VitroxVox 884 — 2y

Answer this question