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

Why does my buy bus script not work properly?

Asked by 6 years ago

Hello. I have been trying trying to make a one time purchase for buses on my game Bus Simulator.I was doing the code and was ready to test it. However, it did not work as i wanted it to. LocalScript:

local Player = game.Players.LocalPlayer
local ExampleEvent = game:GetService("ReplicatedStorage"):WaitForChild("PlaxtonSingle")
local GUIButton = script.Parent

GUIButton.MouseButton1Down:Connect(function()
    if Player.vehStats.PlaxtonOwned.Value >= 1 then
        ExampleEvent:FireServer()
        script.Parent.Text = "Success!"
        wait(1)
        script.Parent.Parent.Parent.ScrollingFrame.Visible = false
        script.Parent.Parent.Visible = false
    elseif Player.leaderstats.Money.Value >= 9000 then 
        ExampleEvent:FireServer()
        script.Parent.Text = "Success!"
        wait(1)
        script.Parent.Parent.Parent.ScrollingFrame.Visible = false
        script.Parent.Parent.Visible = false
        Player.vehStats.PlaxtonOwned.Value = 1
        Player.leaderstats.Money.Value = Player.leaderstats.Money.Value -9000
    end                 
end)

as you can see i want to know if the player owns the plaxton already using a value. However, if the player has not bought it it buys it for the player and changes the value to 1. I play the game and i have 555,555 money i spawn it and i sais success however i do not loose any money at all when i have 0 on the PlaxtonOwned value. Then when i put the value to 1 i try to spawn it and it does not work like i dont have enough money or own it. Please help i really want to get this to work.

1 answer

Log in to vote
0
Answered by 6 years ago

Here's to get you started:

You should store important values such as Money in ServerStorage as their are some exploits which can exploit leaderstat values as they're clientsided or something.

When purchased, fire a RemoteFunction to purchase the bus, and check if the player has the bus or not. (possibly creating an BoolValue in ServerStorage or something?) If the player has enough money and they money - the price is greater than 0 then return success to the client and subtract the price amount from the money on the server.

If you need more help add me on Discord - Goat#2976

Ad

Answer this question