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)

01local button = script.Parent
02local plr = game.Players.LocalPlayer
03local processEvent = workspace:WaitForChild("processEvent")
04local cost
05local Type
06button.Activated:Connect(function()
07    Type = "Jump"
08    cost = 50
09    local process = function()
10 
11        processEvent:FireServer(plr, cost, Type)
12        print("plr, cost, type = " .. plr.Name,cost,Type)
13    end
14 
15    local guiUpdate = function()
16 
17    end
18    process()
19end)

A part of the leaderstats script

01local tf = true
02    processEvent.OnServerEvent:Connect(function(plr, plr, cost, Type)
03        print("receiced")
04        if Type == "Jump"  and tf == true then
05            tf = false
06            print("receiced")
07            if  game.Players:WaitForChild(plr.Name):WaitForChild("leaderstats"):WaitForChild("Coins").Value >= cost*game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value then
08                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
09                game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value = game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value + 1
10                game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpPower").Value = 50 + 3 * game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpLevel").Value
11                workspace:WaitForChild(plr.Name).Humanoid.JumpPower = game.Players:WaitForChild(plr.Name):WaitForChild("Folder"):WaitForChild("JumpPower").Value
12            end
13            tf = true
14        else
15 
16        end
17    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