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

Why does my upgrade shop break in multiplayer?

Asked by 4 years ago

Local script (Button)

local button = script.Parent
local plr = game.Players.LocalPlayer
local processEvent = workspace:WaitForChild("processEvent")
local cost
local Type
button.Activated:Connect(function()
    Type = "Jump"
    cost = 50
    local process = function()

        processEvent:FireServer(plr, cost, Type)
        print("plr, cost, type = " .. plr.Name,cost,Type)
    end

    local guiUpdate = function()

    end
    process()
end)


A part of the leaderstats script

local tf = true
    processEvent.OnServerEvent:Connect(function(plr, plr, cost, Type)
        print("receiced")
        if Type == "Jump"  and tf == true then
            tf = false
            print("receiced")
            if  game.Players:WaitForChild(plr.Name):WaitForChild("leaderstats"):WaitForChild("Coins").Value >= cost*game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value then
                game.Players:WaitForChild(plr.Name):WaitForChild("leaderstats"):WaitForChild("Coins").Value = game.Players:WaitForChild(plr.Name):WaitForChild("leaderstats"):WaitForChild("Coins").Value - game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value*cost
                game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value = game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value + 1
                game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpPower").Value = 50 + 3 * game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value
                workspace:WaitForChild(plr.Name).Humanoid.JumpPower = game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpPower").Value 
            end
            tf = true
        else

        end
    end)

All the values get multiplied by the number of players (I think) but I'm not sure how to fix it.

1 answer

Log in to vote
0
Answered by 4 years ago

I simply removed the part of the leaderstats script from the PlayerAdded function.

Ad

Answer this question