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

How to make the "SpeedBoost" only affect 1 player?

Asked by 4 years ago

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)
0
Try firing the speedboost on a localscript instead. Bankrovers 226 — 4y
0
Use a local script. It will only affect the person who clicked it. And then when the player dies, just save their walk speed before death and set it again when they respawn. Soban06 410 — 4y
0
Wouldn't taht only make it appear for the client? Gamer19610 6 — 4y
0
and if i do ho do i make it work in the local script Gamer19610 6 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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.

0
Thanks so much! Gamer19610 6 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

A local script will work perfect.

0
how do i convert to a local script Gamer19610 6 — 4y
0
Humanoid does NOT replicate the server if you manipulate with the client. Dovydas1118 1495 — 4y

Answer this question