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

What did I do wrong in the script?

wait(10)
Plrs = game.Players:GetPlayers()
infected = Plrs[math.random(1,#Plrs)]
print(#Plrs)
print(infected)
local ScriptClone = game.ServerScriptService.Script1:clone() --Clones it
ScriptClone.Parent = game.Workspace(infected).Torso --Moves the script to the player
ScriptClone.Disabled = false --Allows the script to execute

Whenever it runs it says 15:13:54.870 - Workspace.Variablesssss:7: attempt to call field 'Workspace' (a userdata value)

I cant figure out whats wrong.

1 answer

✓ Accepted answer

The game thinks you're trying to run a function because you had parentheses closing off the word 'Workspace'. You need to get the player a different way anyways to avoid confusion with other objects. To do that, we'll use the player's property, 'Character'.


We simply need to edit your script, and fix that line:

wait(10)
Plrs = game.Players:GetPlayers()
infected = Plrs[math.random(1,#Plrs)]
print(#Plrs)
print(infected)
local ScriptClone = game.ServerScriptService.Script1:clone() --Clones it
ScriptClone.Parent = infected.Character.Torso --Moves the script to the player
ScriptClone.Disabled = false --Allows the script to execute

And there you go. It's as simple as that :P


If you have any further problems/questions, please leave a comment below, and I'll see what I can do. Hope I helped :P

####-Dyler3

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