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

What is wrong with my humaniod speed script?

Asked by 10 years ago
local hum = findFirstChild("Humanoid")
hum.Walkspeed = 0

When I use this script, players can still move. Can someone help?

I got this is output

Workspace.Map_Changer:88: attempt to call global 'FindFirstChild' (a nil value)

4 answers

Log in to vote
0
Answered by
lomo0987 250 Moderation Voter
10 years ago

First off, I take it this is located within a local script of a player. If so, you will want it to wait until it finds the the player.

Here, try this script..

repeat wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer
local hum = player.Character.Humanoid

if hum.WalkSpeed == 16 then
hum.WalkSpeed = 0 
end

This should work.

Edit:

After looking at what you said for the error, it looks like it's not in a local script for the player.

What you will want to do is define the player then define the humanoid like I did at top. It won't be hard to edit.

Ad
Log in to vote
0
Answered by 10 years ago
wait(.1)
P = game.Players.LocalPlayer
H - P.Character:FindFirstChild("Humanoid")
if H then
H.WalkSpeed = 0
elseif H.WalkSpeed == 0 then
H.WalkSpeed = 16
end

Hope I helped!

0
And no I did not forget an end if you use elseif instead of else you don't need an end fireboltofdeath 635 — 10y
0
Lomo's would work but it would break if the player didn't have a humanoid (Destroyed by a script) fireboltofdeath 635 — 10y
Log in to vote
0
Answered by 10 years ago

You didn't set it to find where the Humanoid is, the script is thinking Where do I find the Object named Humanoid? Is it in workspace, script.Parent, or where?!, thus the script didn't work. Heres what you'd do;

Figure=script.Parent:FindFirstChild("Humanoid") --This would be in the Character
if Figure~=nil then
Figure.WalkSpeed=0
end

I hope this helped!

Log in to vote
0
Answered by 10 years ago

You should probably explain the answer to him, to help him learn. The error is saying you aren't connecting the FindFirstChild() method to anything, thus it is nil.

To do this, you must first define humanoid. This would run in a LocalScript in StarterPack.

plr = game.Players.LocalPlayer;
h = plr:FindFirstChild("Humanoid", true);

Now, we'll reference those objects and set the walkspeed :

if h then
h.WalkSpeed = 0;
end

Hope this helped.

Answer this question