SetAttribute not working

The first loacl script in StarterGui

“joinMenuScript”

local playButton = joinMenuSgui.playButtonjoinmenu

Player = game.Players.LocalPlayer

Player:SetAttribute("playbuttonclicked", false)

playButton.MouseButton1Click:Connect(function()
	Player:SetAttribute("playbuttonclicked", true)
end)

The second local script in StarterGui

“steveDialogueScript”

Player = game.Players.LocalPlayer

if Player:GetAttribute("playbuttonclicked", true) then
	print("works")
end

There are no errors in the output, this simply just does not print “works”.

1 Like

The if statement only runs once, before the attribute is set.

I tried a while loop to fix this issue but it just exhausted. I don’t know any other ways of running code multiple times without it exhausting like that - what do I do?

All your Attribute commands are correct. But, your logic is a bit off. When you add the Attribute the first time that is now the default. So when you reset the player, that’s how it will start out.

In your 1st script swap the true and false around and it will come up true. As true would now be the default.

Instead of testing for true or false test if it’s there at all.

Try this …

local playButton = joinMenuSgui.playButtonjoinmenu

Player = game.Players.LocalPlayer

-- Player:SetAttribute("playbuttonclicked", false)

playButton.MouseButton1Click:Connect(function()
	Player:SetAttribute("playbuttonclicked", true)
end)

btw … this isn’t a guess.

1 Like

GetAttribute() is used to get or find an attribute.

SetAttribute() is used to set a value to that attribute.

The attributes work, but don’t work as you thought they would.

1 Like

Add a delay, such as playButton.AttributeChanged:Wait()