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

Making mess with RemoteEvents, Scripts and LocalScripts. Help me!?

So.

To begin, I want to say, that I have a Localscript and a saving leaderstats Script. I can't modify leaderstats with localscript, because they aren't saving. In order to save, I need to modify them with a server script. But! There is a huge problem.

I can't modify player leaderstats through Script (if you know a way, leave an answer asap!)

and

I can modify leaderstats through LocalScript, but they won't save, because the "Changed" event for leaderstats isn't registering when LocalScript is modifying values.

`` I tried to explain as best, as I could, please respond if you know!

1 comment

0

You can modify leaderstats through a script. game.Players.Player.leaderstats.Money.Value = 5

1 answer

✓ Accepted answer

Although sending your script would be nice, I'll do my best.

GLOBAL (Server/Normal Script):

local statsChanged = game.ReplicatedStorage.statsChanged -- This assumes you have a "RemoteEvent" called "statsChanged" in ReplicatedStorage
statsChanged.OnServerEvent:connect(function(plr,points)
	local leaderstats = plr.leaderstats
	local savepoints = leaderstats:FindFirstChild("points")
	savepoints.Value = points
end)

LOCALSCRIPT:

local points = pointstoaddidk
local statsChanged = fgame.ReplicatedStorage.statsChanged
-- I'll assume "points" will be a "NumberValue"
points.Changed:connect(function()
	statsChanged:FireServer(points)
end)

This situation doesn't look to unstable, so if you could send a script to base my scripts off of, that'd be grand.

Or actually do something similar to what LawlR said in your comments: GLOBAL (Server/Normal Script):

local players = game.Players
for i,plr in pairs(players:GetChildren())
	plr.leaderstats.Money.Value = plr.leaderstats.Money.Value + 5
end

The simple script above will add "5" to all players' money.

5 comments

0

If in script I do sth like: player.leaderstats.Cash.Value it shows game.Players.NICK.leaderstats.Cash is not a valid member of player. If I do :WaitForChild("Cash") it is infinite yielding

0

Do you have a script that adds leaderstats to players?

0

Yeah, duh!

0

Make sure you're creating the leaderstats in a server script.

0

I am

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