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

How to fix this +exp gui so it doesn't increases everyone's exp and decrease everyone's mana?

Asked by
Knqe 23
4 years ago

It needs to be a remote event or else the filtering will block it.

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.ExpUp:FireServer()
end)
game.Players.PlayerAdded:Connect(function(player)

game.ReplicatedStorage.ExpUp.OnServerEvent:Connect(function()   
    local exp = player:WaitForChild("Leaderstats")["Exp"]
    local mana = player:WaitForChild("Mana")
    local manac = player:WaitForChild("Manac")
    if mana.Value >= 5 then
    exp.Value = exp.Value + 20
    mana.Value = mana.Value - 10
    end
end)
end)
0
Wait so doesn't increase everyones exp and decreases everyones mana or doesnt increase everyones exp and mana?? greatneil80 2647 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Ok, so the problem here is that you increase the EXP and mana of the player in the players.PlayerAdded event, this means that everyone in the game will get exp and mana instead of that one player. What you should add the EXP and mana to the player who clicks the button(ExpUp event). Also, you really shouldn't place the ExpUp event inside the player added event, just put it outside.

game.Players.PlayerAdded:Connect(function(player) - you were using this player
    --fires every time a player is added--

end)

game.ReplicatedStorage.ExpUp.OnServerEvent:Connect(function(clickedplayer) 
-- use clicked player instead, they are sent instantly when fireserver is used in a localscript
    local exp = clickedplayer:WaitForChild("Leaderstats")["Exp"]
    local mana = clickedplayer:WaitForChild("Mana")
    local manac = clickedplayer:WaitForChild("Manac")
    if mana.Value >= 5 then
     exp.Value = exp.Value + 20
         mana.Value = mana.Value - 10
    end
end)
0
Thank you, but I didn't know that something like this would work. Knqe 23 — 4y
Ad

Answer this question