Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

Wait so doesn't increase everyones exp and decreases everyones mana or doesnt increase everyones exp and mana??

1 answer

✓ Accepted answer

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)

1 comment

0

Thank you, but I didn't know that something like this would work.

This discussion is preserved as it was. New answers, comments, and votes are closed.