Hello fellow devs!
Currently I am developing Samurai Era
where I want to enable horse assault if a player ride on certain horses.
Requirements:
- Horse assault should be executed only when Left Shift key is pressed and held, and
Spirit Meter is 0.1 or more in X scale.
(Spirit Meter is like a Health Bar and recover at certain speed. I want to introduce this
so that the horse assault should not be available all the time.) - While the horse assault is implemented, Spirit should be reduced faster than its recovery speed.
The area enclosed by the red frame in the script is the part I mentioned.
userInputService.InputBegan:connect(function(inputObject, gameProcessedEvent)
if not gameProcessedEvent then
if inputObject.KeyCode == Enum.KeyCode.W or inputObject.KeyCode == Enum.KeyCode.Up then
movement = Vector3.new(movement.X, movement.Y, -1)
elseif inputObject.KeyCode == Enum.KeyCode.S or inputObject.KeyCode == Enum.KeyCode.Down then
movement = Vector3.new(movement.X, movement.Y, 1)
elseif inputObject.KeyCode == Enum.KeyCode.A or inputObject.KeyCode == Enum.KeyCode.Left then
movement = Vector3.new(-1, movement.Y, movement.Z)
elseif inputObject.KeyCode == Enum.KeyCode.D or inputObject.KeyCode == Enum.KeyCode.Right then
movement = Vector3.new(1, movement.Y, movement.Z)
elseif inputObject.KeyCode == Enum.KeyCode.Space then
local ray = Ray.new(horse.HumanoidRootPart.Position + Vector3.new(0, -4.3, 0), Vector3.new(0, -1, 0))
local hit, position = game.Workspace:FindPartOnRay(ray, horse)
if hit and hit.CanCollide then
horse.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
elseif inputObject.KeyCode == Enum.KeyCode.E then
humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
elseif inputObject.KeyCode == Enum.KeyCode.LeftShift then
if spiritDisplay.Size.X.Scale > 0.1 then
spiritDisplay.SpiritLocalScript.Disabled = true
sprint = true
horse.FrontGuard.Transparency = 0.8
horse.Humanoid.WalkSpeed = 60
--local force = Instance.new("ForceField")
--force.Parent = horse
horse.Body.Touched:Connect(function(hit)
local cooldown = false
if hit.Parent:WaitForChild("Humanoid") and sprint and not cooldown then
cooldown = true
local hum = hit.Parent.Humanoid
hum.Health -= 5
local cloneNumber = damageEffect:Clone()
cloneNumber.TextLabel.Text = "-5"
cloneNumber.Parent = hit.Parent
wait(3)
cloneNumber:Destroy()
cooldown = false
end
end)
end
end
end
end)
I also post the script for Health GUI for your reference.
local spiritDisplay = script.Parent
while spiritDisplay.Size.X.Scale < 1 do
spiritDisplay.Size = UDim2.fromScale(spiritDisplay.Size.X.Scale+.02, 1)
wait(1)
end
The horse assault is not executed when I press and hold Left Shift key while
Spirit meter is more than 0.1 in scale.
And no error message is shown for this.
I will appreciate if someone help me.