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

how to change a value for a specific player from the server side?

i want to change a value from the server side for a specific player when the player clicks the button this is the main script for it (not the script for button it is main script)

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function(click)
    if player.leaderstats.Money.Value >= 70 then
        player.leaderstats.Money.Value = player.leaderstats.Money.Value - 70
      
        game.Workspace.Backpack.Capacity.Value = 20
    end
end)

this does change the value but not from the server side and i tried it by going on the server side myself then i changed the value and it worked but it changed the value for everyone please help me

1 answer

✓ Accepted answer

Create a Remote Event, and Place it into ReplicatedStorage

Local Script

local buyItems = game.ReplicatedStorage.RemoteEvent
local WeaponPrice = 70

script.Parent.MouseButton1Click:Connect(function(click)
	buyItems:FireServer(WeaponPrice)
end)

Server Script

local buyItems = game.ReplicatedStorage.RemoteEvent

buyItems.OnServerEvent:Connect(function(player, WeaponPrice)
    if player.leaderstats.Money.Value >= WeaponPrice then
        player.leaderstats.Money.Value = player.leaderstats.Money.Value - WeaponPrice

        game.Workspace.Backpack.Capacity.Value = 20
    end

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