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

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

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

✓ Accepted answer

Add a RemoteEvent in ReplicatedStorage

LocalScript:

RemoteEvent:FireServer(updatedValue)

Server Script:

RemoteEvent.OnServerEvent:Connect(function(player, updatedValue)
	player.leaderstats.Money.Value = updatedValue
end)

5 comments

0

Is there any way I would be able to efficiently do this for multiple players?

0

This should work just fine for multiple players as it is

0

Oops, I didn't mean players, I meant GUIs.

0

(Multiple of the same GUI)

0

(I.e. a shop GUI, different items so different costs but same GUIs)

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