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

[FE] Why won't my tools go into the players backpack?

I get the error "Attempt to set parent of Players.BelgiumStorage to Players.BelgiumStorage.Backpack would result in circular reference"

LocalScript in StarterGui

local Storage = game.ServerStorage
local Sword = Storage.Sword
local Cane = Storage.Cane

function onPlayerAdded(player)
	player.CharacterAdded:connect(function()
			if player:GetRankInGroup(2972225) >= 253 then
					game.ReplicatedStorage.ServerEvents.GiveToolsA:FireServer(player, Sword, Cane)
				end
			end)
	end

for _, player in pairs(game.Players:GetPlayers()) do
	onPlayerAdded(player)
end

game.Players.PlayerAdded:connect(onPlayerAdded)

Script in ServerScriptStorage

local function GiveToolsAdmin(Player, Sword, Cane)
	Sword:Clone()
	Cane:Clone()
	Sword.Parent = Player.Backpack
	Cane.Parent = Player.Backpack
end

game.ReplicatedStorage.ServerEvents.GiveToolsA.OnServerEvent:Connect(GiveToolsAdmin)

1 answer

There's no need to pass a player argument because the client is already always passed as the first parameter in an OnServerEvent event. Your error happened because the "Sword" parameter in your GiveToolsAdmin function is actually the player!

But really, there's no need to use remotes here at all. Parent the top script to ServerScriptStorage, and combine them and you should be good.

Also - connect is deprecated. Use Connect!

local Storage = game.ServerStorage
local Sword = Storage.Sword
local Cane = Storage.Cane

function onPlayerAdded(player)
	player.CharacterAdded:Connect(function()
		if player:GetRankInGroup(2972225) >= 253 then
			Sword:Clone().Parent = player.Backpack
			Cane:Clone().Parent = player.Backpack
		end
	end)
end

game.Players.PlayerAdded:Connect(onPlayerAdded)

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