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

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

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

✓ Accepted answer

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

1 comment

0

Thanks!

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