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

Why is the Parent attribute of this Folder expecting a string not an Instance?

invalid argument #2 (string expected, got Instance)

On line 6

Server script

game.ReplicatedStorage.clientPipeline.Broadcast.openBroadcast.OnServerInvoke = function(player, Id)
	local broadcasts = game.ServerStorage.broadcasts:GetChildren()
	for i=1,#broadcasts do
		if broadcasts[i].Id.Value == Id then
			local x = broadcasts[i]:Clone()
			x.Parent = game.Players[player].PlayerScripts.connectedTo
		end
	end
	return
end

You'd think I would've encountered this error before, especially as its with something as basic as parents, but I haven't and don't know why it wants a string or even why its says argument #2 when there's only one argument.

Any ideas on whats going on?

3 comments

0

i think its something with the ID

0

idk cuz its a string

0

maybe try using :WaitForChild on playerscripts

1 answer

✓ Accepted answer

Using game.Players[player] is actually a function that requires a string (not a player instance) so therefore you should use game.Players[player.Name].

But a shortcut is just to use player

game.ReplicatedStorage.clientPipeline.Broadcast.openBroadcast.OnServerInvoke = function(player, Id)
    local broadcasts = game.ServerStorage.broadcasts:GetChildren()
    for i=1,#broadcasts do
        if broadcasts[i].Id.Value == Id then
            local x = broadcasts[i]:Clone()
            x.Parent = player.PlayerScripts.connectedTo
        end
    end
    return
end

4 comments

0

That seemed to fix it, though its not recognizing that PlayerScripts is in the player. (PlayerScripts is not a valid member of Player)

0

@TTChaos The script doesnt execute on game start so that couldn't be the problem.

0

@TTChaos So apparently the server cant access the PlayerScripts, but I still need to duplicate an instance to a spesific player. How could I do that?

0

In the end I decided to use ReplicatedStorage and just make different folders for each player.

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