Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

LocalScript inside a TextButton doesn't work? [SOLVED]

So I made a shop button with this local script inside

local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if player.leaderstats.Money >= 200 then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value - 200
		local item = game.Lighting.Tool
		local brought = item:Clone()
		brought.Parent = player.Backpack
	else script.Parent.Text = "Not enough money"
wait(.5)
script.Parent.Text = "BUY"
	end 
end)

No error were spotted and if I don't have enough money, the text on the button would stay "BUY" and not "Not enough money". Also if I have enough money it'd stay still. What's the problem here?

4 comments

0

Local scripts will only run if they're a descendant of the player's character, their backpack, playerGui, playerScripts, or the replicatedfirst service. Is the local script a descendant of any of these?

0

it's actually I'm comparing userdata with numbers. it's supposed to be Money.Value >= 200. thank you for helping though

0

Ah. A simple enough mistake. Glad you sorted it out.

0

You should make the item cloning a remote event btw

2 answers

I'm sorry. I was comparing UserData with Numbers. It's supposed to be:

if player.leaderstats.Money.Value >= 200 then

, not > if player.leaderstats.Money >= 200 then Thanks for reading!

problem is at line 3 because you didn't aded .Value change it to this and it will work!

if player.leaderstats.Money.Value >= 200 then

This discussion is preserved as it was. New answers, comments, and votes are closed.