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

A local script not configuring a player stats?

Asked by 4 years ago

Here's the script that's causing the problem.

local rep = game:GetService("ReplicatedStorage")
local playerBobux = game.Players.LocalPlayer.leaderstats.BOBUX.Value

script.Parent.MouseButton1Click:Connect(function()
    local glock = rep.G17

    if playerBobux > 49.99 then
        local glockclone = glock:Clone()

        glockclone.Parent = game.Players.LocalPlayer.Backpack
        playerBobux = playerBobux - 50
    end
end)

Its a script in a button however when I click the button my BOBUX doesn't change or getting the gun, also the output doesn't have any errors. So, unfortunately, I cannot show an error. Can someone please help me with this problem?

1 answer

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

You dont change values on the client. You have to use remote events and sanity checks on the server.

An example of how you would do that

SERVER SIDE

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event

Event.OnServerEvent:Connect(function(Player) --server received event
    local Bobux = Player.Bobux --path to your number value

    -- if 50 is bigger than numbervalue
    if Bobux.Value < 50 then --this is a sanity check
        return --lets return 
    end 

    --if number value is bigger or equal to 50 then
    Bobux.Value -= 50 --we can use -= so its like Bobux.Value = Bobux.Value - 50
end)

CLIENT SIDE

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage.Event

Button.MouseButton1Down:Connect(function()
    Event:FireServer() --lets fire to the server
end)
0
Thanks a bunch! Spookdoggz 42 — 4y
Ad

Answer this question