Help with the script

Players.PlayerRemoving:Connect(function()
	local TeamPart1 = game.Workspace.TeamParts.TeamPart1
	local Attribute = TeamPart1:GetAttribute("Leader")
	
	if Attribute == 1477309404 then
		print("YES")
	else
		print("NO")
	end
end)

I have such a function and it should output “YES” since the attribute value matches the digit(1477309404), but this does not happen. I do not know why this is happening, please tell me.
I’m sorry if it’s written strangely or incorrectly, I use a translator because I don’t know English.

place some print statements before the if statement to see if it is actually working

I checked print(Attribute) and it output the required numbers.

1 Like

Is it printing that when a player is getting removed from the game, or are you printing “YES” or “NO” in another part of this script or any other script?

Try printing this here:

Players.PlayerRemoving:Connect(function()
    print("player left game")
	local TeamPart1 = game.Workspace.TeamParts.TeamPart1
	local Attribute = TeamPart1:GetAttribute("Leader")
	
    print(Attribute)  -- tells you what the variable actually is because if it's nil then it would print NO in the code below

	--[[if Attribute == 1477309404 then
		print("YES")
	else
		print("NO")
	end]]
end)

to see if this function is even getting called.

1 Like

Yes, the function is being called. The Output contains an inscription stating that the player has left the game and the attribute value.

Perhaps it should be

local Attribute = TeamPart1:GetAttribute("Leader").Value

or something? Is every variable correct?

local Team Part 1 = game.Workspace.Team Parts.TeamPart1: it works properly.

Your option with value didn’t help, output: No. :frowning:

Can you send us the output of the script?

Is the Attribute a string or a number?

Try this:

Players.PlayerRemoving:Connect(function()
	local TeamPart1 = game.Workspace.TeamParts.TeamPart1
	local Attribute = TeamPart1:GetAttribute("Leader")
	
	if tonumber(Attribute) == 1477309404 then
		print("YES")
	else
		print("NO")
	end
end)

If this does not work then you have something wrong in either the creation of the Attribute or you never update it.

1 Like

Yes it works! :smile:
Thank you very much and to everyone who tried to help!

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