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

Why is this script erroring, saying I'm attempting to call user data?

Asked by
P100D 590 Moderation Voter
9 years ago
for i in game.Players do
    i.character.Humanoid.health = 0
    i.character.WalkSpeed = 0
    print("Killed " .. p.Name)
end

Basically this kills everyone and then sets their walkspeed to 0. The error is given at the very first line of this code.

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your Problem

On line 1, in the definition of your generic for loop, you put game.Players. That is an object of game - a userdata. But with the syntax of generic fors, it expects it to look like this;

for [variables] in [iterator function] do

In the place where an iterator function should have been, you put a userdata. Hence the error.

How To Fix

Use Pairs as your iterator function, with arguments of a table full of all the players in the game - game.Players:GetPlayers()

Code

for i,v in pairs(game.Players:GetPlayers()) do
    v.Character.:BreakJoints()
end
0
Thanks! P100D 590 — 9y
Ad

Answer this question