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

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

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)

4 comments

0

Try firing the speedboost on a localscript instead.

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.

0

Wouldn't taht only make it appear for the client?

0

and if i do ho do i make it work in the local script

2 answers

✓ Accepted answer

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.

1 comment

0

Thanks so much!

A local script will work perfect.

2 comments

0

how do i convert to a local script

0

Humanoid does NOT replicate the server if you manipulate with the client.

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