I was making a class distribution function in a script in ServerScriptService . The function works fine on the tool distribution function (Using plr.Backpack). But it seems really stubborn on Local script distribution.

The local script is supposed to be cloned and parented into the player's PlayerScripts. Doesn't want to listen.

Code for the Local script clone, needs to be parented to PlayerScripts. (Output error problem)

game.ReplicatedStorage.Specials.OnServerEvent:Connect(function(plr,Loadout)
	for i,v in pairs(game.ReplicatedStorage.Classes.Specials:FindFirstChild(Loadout):GetChildren()) do
		for c,d in pairs(game.ServerStorage.Specials:GetChildren()) do
			if v.Name == d.Name then
				print(d.Name)
				local Clone = d:Clone()
				Clone.Parent = plr.PlayerScripts
			end
		end
	end
end)

The tool distribution script, in the same script as the local script being cloned.(Works)

game.ReplicatedStorage.Weapons.OnServerEvent:Connect(function(plr,Loadout)
	for i,v in pairs(game.ReplicatedStorage.Classes.Weapons:FindFirstChild(Loadout):GetChildren()) do
		for c,d in pairs(game.ServerStorage.Weapons:GetChildren()) do
			if v.Name == d.Name then
				print(d.Name)
				local Clone = d:Clone()
				Clone.Parent = plr.Backpack
			end
		end
	end
end)

6 comments

0

Try doing plr:WaitForChild("PlayerScripts").

0

The PlayerScripts object does not replicate to the server, it is only accessible and viewable on the client.

0

I've tried plr:WaitForChild('PlayerScripts'). But it says infinite wield

0

Well, I've tried the script before. I once worked perfectly, the day after, I loaded it again and it gave me an error.

0

is the first bit of code inside a localscript?

0

Both are in the same script, a server script. The second code is cloning a specific local script.