Im trying to prevent the player from getting to close to another player.
This is my code:
if game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.W) and (TargetPos -Char.HumanoidRootPart.Position).Magnitude < Distance then
Hum.WalkSpeed = 0
else
Hum.WalkSpeed = Class.ToolVariables.NormalSpeed
end
The problem with this is that when the player for example presses W and D, he is still stuck in one place. Is there a way to just disable and enable W.
RunService.Heartbeat:Connect(function()
if ((Humanoid.MoveDirection).Unit.Z > 0) then
Humanoid.WalkSpeed = 0
else
Humanoid.WalkSpeed = Class.ToolVariables.NormalSpeed
end
end)
UserInputService.InputBegan...(function(Input, GameProcessedEvent)
if not GameProcessedEvent and Input.Keycode == ... then
Hum.WalkSpeed = 0
else
Hum.WalkSpeed = ...
end
end)
local UIS=game:GetService("UserInputService")
local player=game:GetService("Players").LocalPlayer
local character=player.Character or player.CharacterAdded:Wait()
local humanoid=character:WaitForChild("Humanoid")
local walkSpeed=humanoid.WalkSpeed
UIS.InputBegan:Connect(function(input,gameProcessedEvent)
if gameProcessedEvent then return end
if input.KeyCode==Enum.KeyCode.W then
humanoid.WalkSpeed=0
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode==Enum.KeyCode.W then
humanoid.WalkSpeed=walkSpeed
end
end)
Try my suggestion … works perfectly and you can add whatever key/press you wish.
(Many attempts with many different ways)
Even figured out one I can use with something I’m doing …
Just stops all Control …
Summary
task.wait(3)
local player=game:GetService("Players").LocalPlayer
local playerScripts = player:WaitForChild("PlayerScripts")
local PlayerModule = require(playerScripts:Waitforchild("PlayerModule"))
local controls = PlayerModule:GetControls()
controls:Disable()
Yes, but your solution is not scalable. What if your game allows your character to run by pressing shift? Now you have to add an if condition in the run script to prevent it from working when the character can’t move forward, but oh no! Now you can’t run backwards, even if that should be possible (we only disabled walking forwards, remember?) and so you have to add another if condition…
The script to stop all control is better, but again, not quite right, as it disables all controls instead of disabling just walking forwards.