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

sell script/ getting leaderstats bug help?

Asked by
raid6n 2196 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

here is the problem, if i click on the screen and then sell it works but when i click again it gives me 2 instead of one my rebirth count is 0 help?

script: (for the click for cash)

local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteData = game:GetService("ServerStorage"):WaitForChild("RemoteData")


local cooldown = .5

replicatedStorage.Remotes.Lift.OnServerEvent:Connect(function(player)

    if not remoteData:FindFirstChild(player.Name) then return "NoFolder" end

    local debounce = remoteData[player.Name].Debounce

    if not debounce.Value then
        debounce.Value = true

        player.leaderstats.Strength.Value = player.leaderstats.Strength.Value + 1 * (player.leaderstats.Rebirths.Value + 1)

        wait(cooldown)

        debounce.Value = false
     end
 end)


local script click to sell gui:

script.Parent.MouseButton1Click:Connect(function()
    --Varibles--
    local player = game.Players.LocalPlayer
    local Cash = player:WaitForChild("leaderstats").Cash
    local Strength = player:WaitForChild("leaderstats").Strength
    --Varibles--
    --Script--
    Cash.Value = Cash.Value + Strength.Value
    Strength.Value = 0
end)

1 answer

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

The issue is you are trying to set your strength locally using a local script. Think of it this way:

The server is the father where all the information is stored (points, money etc.) and each client is a child of the father. If a child decides to pick up more sweets than the father has given him, how is the father meant to know and how are all the other clients meant to know?

You need to remember LocalScript = Client and Script = Server. With this knowledge, use remotes to tell the server (or father if you prefer this analogy) that they are selling and make the change to the leaderboard through the server script.

tl;dr You cannot make changes which everyone sees from a LocalScript. Use a remote to communicate with the server. Example script below:

Client

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

script.Parent.MouseButton1Click:Connect(function()
    SellRemote:FireServer()
end)

Server

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

SellRemote.OnServerEvent:Connect(function (plr)
    if plr:WaitForChild("leaderstats").Strength.Value > 1 then 
        local Cash = plr:WaitForChild("leaderstats").Cash
        local Strength = plr:WaitForChild("leaderstats").Strength

        Cash.Value = Cash.Value + Strength.Value
        Strength.Value = 0
    end
end)
0
Some errors, editing. raid6n 2196 — 5y
0
My apologies, fixed up the errors. Nefarioum 162 — 5y
Ad

Answer this question