First here are my scripts:
Client
local userInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local horseWalkEvnt = ReplicatedStorage.HorseEvents:WaitForChild("HorseWalk")
local turnRightEvnt = ReplicatedStorage.HorseEvents:WaitForChild("TurnRight")
userInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.W and mounted == true then --walk command
walking = true
horseWalkEvnt:FireServer(player)
end
end)
userInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.D and walking == true then --Turn right
print("began")
turnRightEvnt:FireServer(false)
end
end)
userInputService.InputEnded:Connect(function(key)
elseif key.KeyCode == Enum.KeyCode.D and walking == true then --stop turning
print("stopped")
turnRightEvnt:FireServer(true)
end
end)
Server
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local horseWalkEvnt = ReplicatedStorage:WaitForChild("HorseEvents"):WaitForChild("HorseWalk")
local turnRightEvnt = ReplicatedStorage:WaitForChild("HorseEvents"):WaitForChild("TurnRight")
local function turnRight(player,turning) -- turn right
print(turning)
while turning == false do
for x = 1,4,4 do
horse:SetPrimaryPartCFrame(horse:GetPrimaryPartCFrame()*CFrame.fromEulerAnglesXYZ(0,math.rad(-x),0))
end
wait()
end
end
local function horseWalk(player) --Move forward
PlayWalkAnim:Play()
while wait()do
horse:SetPrimaryPartCFrame(horse:GetPrimaryPartCFrame()*CFrame.new(0,0,0-.2))
end
end
horseWalkEvnt.OnServerEvent:Connect(horseWalk)
turnRightEvnt.OnServerEvent:Connect(turnRight)
These scripts are made for controlling a horse. The problem is that the horse would never stop turning after once firing the turnRightEvnt. I have tried many different loops, breaking, and dsiconnecting the function. robloxapp-20200530-2217450.wmv (2.4 MB) Without the lag it would move smoothly. According to the output everything is working fine, but the loop never stops.
Output for one key Code D:
began
false
stopped
true
If I press D again (as I did in the video) the horse starts turning faster. I’m doubting, if this is even the right way to make a horse move…