Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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)
0
If the "money" value is created by the server it must be changed by the server, use a remote event. DinozCreates 1070 — 5y
0
also, you can make your script alot simpler by adding some variables for things like the LocalPlayer theking48989987 2147 — 5y
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. sesamert16 31 — 5y
0
Adorable. So you're creating leaderstats locally? DinozCreates 1070 — 5y
View all comments (11 more)
0
money = money - 10000 smh... use remotes please. greatneil80 2647 — 5y
0
I don't see the problem with using remotes when this works... sesamert16 31 — 5y
0
With not using remotes* sesamert16 31 — 5y
0
read my answer SaltyPotter 362 — 5y
0
FE is enabled - isn't that what makes games hack-proof? That little tick that makes them FE enabled in Workspace? sesamert16 31 — 5y
0
Please read the answer before commenting. Do some research into the issue before assuming that you're correct and we're wrong. DinozCreates 1070 — 5y
0
That's what the answer leads me to believe sesamert16 31 — 5y
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. DinozCreates 1070 — 5y
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. sesamert16 31 — 5y
0
Since you're the smartest person around, i suppose you can figure it out then. DinozCreates 1070 — 5y
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 SaltyPotter 362 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

0
Regardless of whether you have FE set to true it will be in effect. DinozCreates 1070 — 5y
Ad

Answer this question