Script not giving tool

I have a script that gives a user a tool if they’ve been assigned as a staff, I have another script that when a player joins, it checks if they’ve been assigned as staff and if they have, it gives them the staff card tool. However, it doesn’t give them the tool.

Code:

game.Players.PlayerAdded:Connect(function(player)
	if game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId)) then
		local staffCard = game.ServerStorage.StaffCard:Clone()
		staffCard.Handle.SurfaceGui.Frame:WaitForChild("Owner").Text = "Owned by: "..player.Name
		staffCard.Handle.SurfaceGui.Frame:WaitForChild("Role").Text = "Role: "..game.ServerStorage.Staff[tostring(player.UserId)].Value
		staffCard.Parent = player.Backpack
	end
end)

Anything in output?

Nope. Nothing at all. 30 characterssss

Does it wait to check if the Staff Card is in the user’s inventory or whatever?

What exactly do you mean by that?

Like, using WaitForChild() on it to wait for the Staff Card to be in the user’s inventory.

I don’t think I quite understand. In what part of the code would I want to use WaitForChild() on?

if game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId)) then

Oh, that’s to check if the user was assigned. In my assigning script, I make it so it creates a StringValue inside a folder called Staff inside the ServerStorage. I name the StringValue with the person’s user ID.

That just checks if a StringValue with the name of the player’s UserID exists.

Ah, ok. Not sure then. Sorry.

Are you sure that the assigning StringValue action run before the checking action?

Yes I am. This is a PlayerAdded event. I also put a print(“”) and it printed it out meaning the if condition is true. The only part not working is the giving tool.

What I’m thinking is that it’s because the character hasn’t loaded in?

I recommend you add the tool to startergear of that players so they keep it if they reset:

--in this line:
staffCard.Parent = Player:WaitForChild("StarterGear")

But what about rejoining? That’s the whole point of this script.

no just change that line in the script.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function()
    	if game.ServerStorage.Staff:FindFirstChild(tostring(player.UserId)) then
	    	local staffCard = game.ServerStorage.StaffCard:Clone()
		    staffCard.Handle.SurfaceGui.Frame:WaitForChild("Owner").Text = "Owned by: "..player.Name
	    	staffCard.Handle.SurfaceGui.Frame:WaitForChild("Role").Text = "Role: "..game.ServerStorage.Staff[tostring(player.UserId)].Value
		    staffCard.Parent = player.Backpack
    	end
    end)
end)

You may want to do this so that they would receive it every time upon spawning.

1 Like

that is unnecessary just use startergear.

Yeah, that’s what I was thinking. That it may because the character hasn’t loaded in. I was about to do that lol. Let me try it right now.

I think using that is more effective than StarterGear.

Startergear would only be efficient if he intends to give it to all players.