You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I’m trying to make a blocking feature for my RPG game with contextactionservice but I also have a sprinting feature.
- What is the issue? Include screenshots / videos if possible!
If I try blocking while sprinting it doesn’t do anything, but my block function only runs at the end of the input, which is when the player stops blocking.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried checking the userinputstate contextactionservice returns, it only returns Enum.UserInputState.End.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This script only includes the block script, it is client sided. It might be a bit messy as this is an old game I’m picking back up.
local ts = game:GetService("TweenService")
game.Players.LocalPlayer.CharacterAdded:Connect(function(chr)
char = chr
end)
function Block(AN, IS)
print(IS)
if IS == Enum.UserInputState.Begin then
blockanimation:Play()
char.Humanoid.WalkSpeed = 0
game.ReplicatedStorage.Events.Remote.Block:FireServer(true)
elseif IS == Enum.UserInputState.End then
blockanimation:Stop()
if game.Players.LocalPlayer.Stats.WalkSpeed:FindFirstChild("Block") then
game.Players.LocalPlayer.Stats.WalkSpeed.Block:Destroy()
end
local adder = 0
for i, v in pairs(game.Players.LocalPlayer.Stats.WalkSpeed:GetChildren()) do
adder += v.Value
end
char.Humanoid.WalkSpeed = adder
game.ReplicatedStorage.Events.Remote.Block:FireServer(false)
end
end
ctx:BindAction("Block", Block, true, Enum.KeyCode.F, Enum.KeyCode.ButtonY)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
Edit: All good, I managed to fix it.