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

Why does my buy bus script not work properly?

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

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

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