Error gui and sound

So i wanted this script so that when you click a button a error sound will appear with an error gui but i dont know why it’s not working, (intelligence is the currency btw) basically i want to make it so if the player has lower than the amount an error will pop up and then disappear after a few seconds. Thanks anyways!

and then it just says this. image

heres the script:
local player = game.Players.LocalPlayer

if player.leaderstats.intelligence.Value < 500 then
script.Parent.MouseButton1Click:Connect(function(click)
if click then
game.StarterGui.Door.ErrorFrame.Visible = true
script.Parent.error:Play()
wait(1.5)
game.StarterGui.Door.ErrorFrame.Visible = false
end
end)
end

1 Like

Maybe you could try for the leaderstats to load first so it would be:

local player = game.Players.LocalPlayer intelligence = player:WaitForChild("leaderstats"):WaitForChild("intellegince") if intelligence.Value < 500 then script.Parent.MouseButton1Click:Connect(function(click) if click then game.StarterGui.Door.ErrorFrame.Visible = true script.Parent.error:Play() wait(1.5) game.StarterGui.Door.ErrorFrame.Visible = false end end) end

Unfortunately, Your script didn’t fix it but that’s fine! I’ll just wait for the Devforum community to see this post. Thanks anyways! : D

Maybe you forgot to capitalize Intelligence. Can we see your leaderstats script so we know the exact name of the “intelligence” value?

1 Like

No, the name of the intelligence value is intelligence not capitalized.

local dataStore = game:GetService(“DataStoreService”):GetDataStore(“intelligenceData”)

starterintelligence = 0 --This is the starter money

game.Players.PlayerAdded:Connect(function(plr)

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr

local intelligence = Instance.new("IntValue")
intelligence.Name = "intelligence" --Put ur currency name here, mine is Money
intelligence.Value = dataStore:GetAsync(plr.UserId) or starterintelligence
intelligence.Parent = leaderstats

end)

game.Players.PlayerRemoving:Connect(function(plr)

dataStore:SetAsync(plr.UserId, plr.leaderstats.intelligence.Value)

end)

local player = game.Players.LocalPlayer

local leader = player:WaitForChild("leaderstats")
leader:WaitForChild("intelligence")

if player:FindFirstChild("leaderstats") then
	if player.leaderstats.intelligence.Value < 500 then
		script.Parent.MouseButton1Click:Connect(function(click)
			if click then
				game.StarterGui.Door.ErrorFrame.Visible = true
				script.Parent.error:Play()
				wait(1.5)
				game.StarterGui.Door.ErrorFrame.Visible = false
			end
		end)
	end
end

The issue is scripting is running before intelligence creates, so you should add waitforchild for intelligence too.

1 Like

forgot to mention that this is another script, im trying to make it so if you dont have enough an error will pop up, but if u do have enough a door will open.

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
script.Parent.Parent.Visible = false
script.Parent.Coin:Play()

if player.leaderstats.intelligence.Value >= 500 then
    game.Workspace.moneywall.Transparency = 0.75
    game.Workspace.moneywall.CanCollide = false
    player.leaderstats.intelligence.Value = player.leaderstats.intelligence.Value - 500
end

end)