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

Why Wont This Code Work?

For some reason, the code just doesn't do anything after it prints "plr joined", any ideas why? Any other methods of getting this done?

local wings = script.StolidsWings
print('In here')

game.Players.PlayerAdded:connect(function(plr)
	wait(1)
	print('plr joining')
	if plr.Name == 'StolidDarkness' then
		wings:Clone().Parent = plr:WaitForChild('StarterGear')
		wings:Clone().Parent = plr:WaitForChild('Backpack') 
	end
end)

P.S. the script it's trying to copy is a LocalScript

1 comment

0

Is the script that has this code a localscript? PlayerAdded doesn't work in localscripts.

2 answers

try ChildAdded, just replace PlayerAdded with ChildAdded

Well, there is only one problem.

It is a very silly one at that, you set the thing that is getting cloned, wings, to local and it isn't inside of the game.Players.PlayerAdded. etc script itself, therefore it isn't going into it.

Just set "local wings = script.Stolidswings" to "wings = script.StolidsWings"

1 comment

0

Local is just for efficiency, if the variable were created in the function then it would stick in that scope of just that function. However, since it was called outside of the function then it would be recognized by whatever that scope is. Since it is created outside of the function at the top of the script, the scope would be the script.

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