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

Script has multiple issues? (Title would be too long if I elaborated?)

This script is inside of a button that, when clicked, is supposed to lower your Money leaderstat, (it does this) raise a value, and make a GUI pop up on your screen for a short time. (it doesn't do any of this) Originally, the LocationsPercentage was to be raised by 0.05. I tried making it a non-decimal number to see if it would work then, and it did. Why doesn't arithmetic was decimals work? Even with the LocationsPercentage arithmetic working, the GUI doesn't pop up. Nor does it pop up if you don't have $10k. If you click it while your Money stat is under $10k, literally nothing happens. This is especially confusing because I have this script implemented in many other places around the game and it works fine there. What the heck? Edit: The script is a LocalScript, as are all of the scripts where this script works.

script.Parent.MouseButton1Click:Connect(function()
	local Money = game.Players.LocalPlayer.leaderstats.Money
	if Money.Value < 10000 then
		game.Players.LocalPlayer.PlayerGui.Folder.NotEnoughMoneyGui.Frame.Visible = true
		wait(2)
		game.Players.LocalPlayer.PlayerGui.Folder.NotEnoughMoneyGui.Frame.Visible = false
	elseif Money.Value >= 10000 then
		Money.Value = Money.Value - 10000
		game.Players.LocalPlayer.LocationsPercentage.Value = game.Players.LocalPlayer.LocationsPercentage.Value + 0.05
		game.Players.LocalPlayer.PlayerGui.Folder.SuccessfulPurchaseGui.Frame.Visible = true
		wait(2)
		game.Players.LocalPlayer.PlayerGui.Folder.SuccessfulPurchaseGui.Frame.Visible = false
	end
	end)

15 comments

0

If the "money" value is created by the server it must be changed by the server, use a remote event.

0

also, you can make your script alot simpler by adding some variables for things like the LocalPlayer

0

The money being changed is the only thing that DOES work - the problem is the rest of the script. Please read the post before commenting.

0

Adorable. So you're creating leaderstats locally?

0

money = money - 10000 smh... use remotes please.

0

I don't see the problem with using remotes when this works...

0

With not using remotes*

0

read my answer

0

FE is enabled - isn't that what makes games hack-proof? That little tick that makes them FE enabled in Workspace?

0

Please read the answer before commenting. Do some research into the issue before assuming that you're correct and we're wrong.

0

That's what the answer leads me to believe

0

If you keep your values Client side then you're a fool. Likely whats going on is you have them on the server, you're changing them on the client, and since it SHOWS to be changed on the client, you think you're right and they've been changed. You NEED to use a remote event for this to work.

0

The money is NOT the issue. If I have to make LocationPercentage 5 instead of 0.05 that is fine, I can work around that. The issue is the GUI - that part of the script works everywhere but in this one script for whatever reason. I don't see what values, clients, servers, and remoteevents/functions have anything to do with that.

0

Since you're the smartest person around, i suppose you can figure it out then.

0

Well I hope you learn how to store values on the server. If the value doesn't work, then the code beneath it won't work i'd assume

1 answer

You should use variables it makes the code much easier to read.

-- script as a child of 'PlayerGui'
local playerGui,player = script.Parent,script.Parent.Parent
local money = player:WaitForChild("leaderstats").Money
local declined = playerGui:WaitForChild("Folder").NotEnoughMoneyGui.Frame
local success = playerGui.Folder.SuccessfulPurchaseGui.Frame
local locationPercentage = player.LocationsPercentage
local button = playerGui.Button

button.MouseButton1Click:Connect(function() -- when it's easier to read, it's easier to fix.
		if money.Value < 10000 then 
		declined.Visible = true
		wait(2)
		declined.Visible = false
		elseif money.Value >= 10000 then
		money.Value = money.Value - 10000
		locationPercentage.Value = locationPercentage.Value + 0.05
		success.Visible = true
		wait(2)
		success.Visible = false
	end
end) -- use the 'print()' function to debug your script

Also, I don't know if this is a test but you should have FilteringEnabled set to true and you should be keeping your values server-sided and use remote events with values in your game like money especially, else your game will be hacked.

Filtering Enabled info: https://devforum.roblox.com/t/how-do-i-even-go-about-using-filtering-enabled/150072

1 comment

0

Regardless of whether you have FE set to true it will be in effect.

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