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

Leaderstat value changes ONLY on client. How do I fix it?

So, I have made a script for spawning cars thru a GUI, and made it a localscript, so when you press the textbutton you purchase the car, and the second time you press it you spawn it, and what i saw is if you purchase it it will only take the money from client, and when i did print(game.Players.neymarSword.stats.cash.Value) the value was the same as it was before the purchase What i tried is making the script not a localscript, but a normal one, but when i did that - nothing happened

script.Parent.MouseButton1Click:Connect(function()

if script.Parent.Parent.Purchased.Value == true then
	-- Spawn it
	game.ReplicatedStorage.SpawnCar:FireServer(script.Parent.Parent.Name)
else
	-- Let them purchase it	
	local PriceOfItem = game.ReplicatedStorage:WaitForChild("CheckPrice"):InvokeServer(script.Parent.Parent.Name)

	if game.Players.LocalPlayer.stats.cash.Value >= PriceOfItem and script.Parent.Parent.Purchased.Value == false then
		-- The player has enough cash
		game.Players.LocalPlayer.stats.cash.Value = game.Players.LocalPlayer.stats.cash.Value - PriceOfItem
		script.Parent.Parent.Purchased.Value = true
		script.Parent.Text = "Spawn"
	end
end

end)

my script ^

2 comments

0

Recommend firing a remote to a server script when purchasing instead of doing subtracting in a localscript(client-side).

1

What above comment said. Modifying anything within a local script will only affect the client. If you change cash in a local script, server won't see it. If you spawn a car on a local script, server wont see it. You have to use remote events and functions. https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

2 answers

Remember that a LocalScript will only overwrite properties on that client, not anywhere else. Therefore, when a player purchases an item, their Cash will only be affected on the client, not the server. You will need to use a RemoteEvent/Function to affect the Cash value on the server.

3 comments

0

yeah, how exactly do i do it? i just cant figure out remotes, i tried watching some videos, although it didn't help me

0

Remotes are simple. I provided a link to a very detailed wiki guide for them. If that page can't help you, then you need to go back and learn more before trying to tackle events. They are simple, just actually have to read and learn from the sources provided to you.

0

^^^^^^^^^^

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