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

Leaderstats broken when changed by local script?

I would like to note first there is no problem with my script, rather it is a roblox server problem I think and what I'm trying to portray below isn't a script.

This is has been my biggest problem so far, I have a GUI that changes a person's leaderstats(e.g stage = 1,2,3 etc) a simple IntValue to keep track of what stage a person is...

Now when I check to see how my script is running in Test -> Local Server -> 1 Player

There's usually 2 more roblox studio that pops up, 1 for the server and another for the 1 Player.

I check the Explorer's Tab and Properties Tab for the Local Server and here is what I see:

(THIS IS NOT A SCRIPT) LOCAL SERVER:

------------------EXPLORER TAB-----------------------
Players
	'->Player1
		'->LeaderStats
			'->stage
-----------------------------------------------------------------

----------------PROPERTIES TAB----------------------- Value = 0

I click the Next Stage Button on the Player1 Studio and I see the Value of the Stage increase to 1 FOR THE PLAYER1 STUDIO ONLY.

I checked back to see if the Server Studio changed, and it still remains the same!

I think the problem here is I'm using a local gui, therefore the Server Studio cannot see the changes, BUT my GUI won't work if I won't use a LocalScript.

I would need some advice regarding this matter, or a solution to my problem would also help.

(P.S Sorry for the bad explanation)

1 answer

✓ Accepted answer

Is filtering enabled turned on? If yes, then you need to make a remote event to do that, as local scripts only work for the client and not the server. It's simple. Just insert a remote event to ReplicatedStorage and call it whatever you want.

Here's the script for the gui:

local button = script.Parent

button.MouseButton1Click:Connect(function()
	game:GetService("ReplicatedStorage").RemoteEvent:FireServer(1) --the one is how much stages you want to add
end)

Now add another script at the ServerScriptService and put this code

game:GetService("ReplicatedStorage").RemoteEvent.OnServerEvent:Connect(function(player, amount)
	game.Players[player.Name].leaderstats.Stage.Value = game.Players[player.Name].leaderstats.Stage.Value + amount
end)

And if I make any spelling differences, just edit them!

I highly recommend you to learn more about remote events, as they are super helpful :)

3 comments

0

I'll try this out, thank you.

0

Althought your script did not work. I tried learning about remote events and successfully it did the job. Thank you

0

It was probably cause of spelling differences, but in the end it still worked! Glad could help :)

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