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

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

Asked by
NorteX_tv 101
5 years ago

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!

0
You can modify leaderstats through a script. game.Players.Player.leaderstats.Money.Value = 5 LawlR 182 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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.

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 NorteX_tv 101 — 5y
0
Do you have a script that adds leaderstats to players? Cvieyra2test 176 — 5y
0
Yeah, duh! NorteX_tv 101 — 5y
0
Make sure you're creating the leaderstats in a server script. LawlR 182 — 5y
0
I am NorteX_tv 101 — 5y
Ad

Answer this question