Script works fine, but won't parent the tool to the player

image

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	local winners = {35782912} -- 35782912
	
	if table.find(winners,player.UserId)then
		print("yay"..player.Name)
		local trophy = script:WaitForChild("Trophy"):Clone()
		trophy.Parent = player:WaitForChild("Backpack")
		print("I work")
	end

end)

There aren’t any errors, and all the prints work, the trophy is just not showing up in the player’s backpack. I tried adding WaitForChilds to see if that would resolve the issue, but it’s still broken.

1 Like

Could you place the winners table outside the PlayerAdded event and try again?

Yea, that didn’t fix it though.

So the issue is that everything gets printed, even the prints after giving the tool, but nothing is given if I understand correctly?

Yes, that is correct, everything is printed fine, but for some reason the player isn’t given the tool

Try thsi perhaps?

local Players = game:GetService("Players")

local winners = {35782912} -- 35782912

local trophy = script:WaitForChild("Trophy")

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	
	if table.find(winners,player.UserId)then
		print("yay"..player.Name)
		trophy:Clone().Parent = player.Backpack
		print("I work")
	end

end)

It’s still breaking, kind of an odd issue to be honest

Maybe change script:WaitForChild("Trophy") to script.Trophy?

Yea, I’ve already tried that, it was originally that, but I changed it to see if WaitForChild would fix it. I actually decided to test just the clone part, without the table find part, and for some reason, I think the clone command is the issue, because it isn’t running.

So even without the table.find, it was still not cloning it? That’s odd

Yea, I removed the table.find part, and the end that goes with it, I did keep the variables, but I didn’t think the variables would really matter

1 Like

Maybe try to put the Trophy tool somewhere else like ReplicatedStorage and try again? It could be the location of it that’s causing it

I would recommend doing this as well with moving it into ReplicatedStorage

local Players = game:GetService("Players")

local winners = {35782912} -- 35782912

local trophy = game.ReplicatedStorage:WaitForChild("Trophy")

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	
	player.CharacterAdded:Wait()
	
	if table.find(winners,player.UserId)then
		print("yay"..player.Name)
		trophy:Clone().Parent = player.Backpack
		trophy:Clone().Parent = player.StarterGear
		print("I work")
	end

end)

So it gives the tools in StarterGear and Backpack so you don’t have to give it everytime the player respawns

Could it be a possibility that it clones even though the character isn’t fully loaded? Try using a CharacterAdded event under PlayerAdded and above table.find

Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        if table.find(winners,player.UserId) then
            -- Stuff
        end
    end)
end)
local Players = game:GetService("Players")
local winners = {35782912} -- 35782912
local trophy = script:WaitForChild("Trophy")

Players.PlayerAdded:Connect(function(player)
	print(player.Name .. " joined the game!")
	
	if table.find(winners,player.UserId)then
		print("yay"..player.Name)
		local PlrChar=player.Character or player.CharacterAdded:wait()
		local NewTrophy=trophy:Clone()
		NewTrophy.Parent = player:WaitForChild("Backpack")
		print("I work")
	end

end)

I actually tried adding that, but it didn’t work out either, this is the script with CharacterAdded

local Players = game:GetService("Players")

local winners = {35782912} -- 35782912

local trophy = script:WaitForChild("Trophy")

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
	print(player.Name .. " joined the game!")
	if table.find(winners,player.UserId)then
		print("yay"..player.Name)
		trophy:Clone().Parent = player.Backpack
		print("I work")
	end
end)
end)

Try whatI did out, it’s similar to yours and it worked for me.

Move it into ReplicatedStorage and use the code that I made

1 Like

I tried that, it didn’t work unfortunately, I’m not sure how much this will help, but the script is currently located in ServerScriptService

I second this comment. Had a problem that involved using ServerStorage when trying to replicate a model to a player (Welding body Armor), and moving the armor folder to ReplicatedStorage solved this problem. As the tool is a child of the Script, when the script runs, it may be causing the tool to become nil.

I recommend changing the location of the Trophy to ReplicatedStorage. As it will be a CLONED tool, therefor replicated.

1 Like

Worked fine when run directly from the workspace (where I tested it) so it must be a problem with where the script is run from.

That worked out for me, thanks!

1 Like