Checking For Folder Children on PlayerAdd: Not Working

When a player purchases a sword, it gets added to their “OwnedSwords” folder as a StringValue and the name of the sword is set as the StringValue name.

I have a function that checks if the player owns the sword when they join, and if they do not it should print "Does not own Spartan Sword"

However, it does not print anything out, please be mindful that this is a LocalScript. I’ve provided the function code below, any advice or insight on how I could resolve this issue would be greatly appreciated, thanks. :cool:

local function checkforOwnership(player)
	if player:WaitForChild("OwnedSwords"):FindFirstChild("Spartan Sword") then
		print("Owns: Spartan Sword")
		equipButton.Visible = true
	else
		print("Does not own: Spartan Sword")
	end
end

game.Players.PlayerAdded:Connect(function(player)
	checkforOwnership(player)
end)

There are also no errors in the output for this, if you were wondering.

You don’t need the PlayerAdded function

1 Like

Thanks alot, this resolved it for me.

I’m fairly new to scripting, does the PlayerAdded function not work within LocalScript’s? I don’t see why it shouldn’t have worked in that instance.

Not actually sure if it doesn’t work on the client. It’s just that there was no need to run the function when the player joined, because the local script would run the player joined regardless of the PlayerAdded.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.