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

How would I change leaderstats values/values in the player inside of a LocalScript?

Asked by
Vid_eo 126
5 years ago

How would I change leaderstats values/values in the player inside of a LocalScript? The values change but only for the player, not for the whole server. How would I make them change for the whole server (i.e. a Shop GUI script). Here's part of my current shop GUI:

LOCAL SCRIPT

local cost = 100
local buyButton = script.Parent
local deb = false
local plr = game.Players.LocalPlayer

function purchasedText()
    if buyButton.Parent.itemOwnedValue.Value == true then
        buyButton.Parent.ImageColor3 = Color3.new(46/255, 213/255, 115/255)
        buyButton.Parent.buyButton.Text = "Bought"
    end
end

purchasedText()

buyButton.MouseButton1Down:connect(function()
    deb = true
    if plr.leaderstats.Money.Value >= cost and buyButton.Parent.itemOwnedValue.Value == false then
        plr.leaderstats.Money.Value = plr.leaderstats.Money.Value - cost
        buyButton.Parent.itemOwnedValue.Value = true
        plr.danceFolder.idkDance.Value = true
        script.Parent.Parent.ImageColor3 = Color3.new(46/255, 213/255, 115/255)
        script.Parent.Parent.buyButton.Text = "Purchased"
    elseif buyButton.Parent.itemOwnedValue.Value == true then
        buyButton.Text = "Already Owned!"
        wait(1.25)
        buyButton.Text = "Bought"
    elseif plr.leaderstats.Money.Value < cost and buyButton.Parent.itemOwnedValue.Value == false then
        buyButton.Text = "You need "..cost - plr.leaderstats.Money.Value.. " more Money to buy this!"
        wait(1.5)
        buyButton.Text = "Buy"
    end
    deb = false
end)

It makes the value in dancesFolder true, but only for the player, not the server. How would I make that value change replicate to the server? (FE Enabled)

1 answer

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

Add a RemoteEvent in ReplicatedStorage

LocalScript:

RemoteEvent:FireServer(updatedValue)

Server Script:

RemoteEvent.OnServerEvent:Connect(function(player, updatedValue)
    player.leaderstats.Money.Value = updatedValue
end)
0
Is there any way I would be able to efficiently do this for multiple players? Vid_eo 126 — 5y
0
This should work just fine for multiple players as it is User#1007 6 — 5y
0
Oops, I didn't mean players, I meant GUIs. Vid_eo 126 — 5y
0
(Multiple of the same GUI) Vid_eo 126 — 5y
0
(I.e. a shop GUI, different items so different costs but same GUIs) Vid_eo 126 — 5y
Ad

Answer this question