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

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

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

✓ Accepted answer

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)

1 comment

0

Thank you! I wish I had known this beforehand, the parent thing was a very stupid idea too be honest.

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 comment

-1

No.. this isn't even near what he asked you just copy & pasted a template.

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