Hello! I have made a shop with a "SpeedBoost button" taht works perfectly but when you buy it it affects all players in the game, it also resetts when the player dies. Can anyone help?
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) local humanoid = character.Humanoid game.ReplicatedStorage.ToolEvents.SpeedBoostEvent.OnServerEvent:Connect(function(player) if player.leaderstats.Coins.Value >= 1500 then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1500 --game.ServerStorage.Tools.JumpBoost:Clone().Parent = player.Backpack humanoid.WalkSpeed = 24 end end) end) end)
Place the remote event OUTSIDE of the characteradded and playeradded.
game.ReplicatedStorage.ToolEvents.SpeedBoostEvent.OnServerEvent:Connect(function(player) local humanoid = player.Character:WaitForChild("Humanoid") if player.leaderstats.Coins.Value >= 1500 then player.leaderstats.Coins.Value = player.leaderstats.Coins.Value - 1500 humanoid.WalkSpeed = 24 end end)
The main reason why is because the other events will finish firing, and so the remote event is unnecessary. If you put it outside, it will set its priority to the remote event, and the walls that are blocking the remote event (e.g. PlayerAdded, CharacterAdded) will be removed.
A local script will work perfect.