-
What do you want to achieve? Keep it simple and clear!
I am trying to make a block system whenever the player presses f. It doesn’t work after the player resets or die -
What is the issue? Include screenshots / videos if possible!
It doesn’t work anymore after resetting.
https://gyazo.com/d0f8a2d3080de1ae7b4a416eed24fea1
i was press f and it doesn’t work
https://gyazo.com/6a183ffab08c11a2ade0b5c1ecc36601
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried placing the UserInputService function in front, which didn’t work
I did a lot of research on this and none of them seem to help
this is my current code for the block system, it is not my full code, ignore the camera shake
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Tool = script.Parent
local AnimationsFolder = Tool:WaitForChild("Animations")
local UserInputService = game:GetService("UserInputService")
local ToolEquipped
local timeSinceLastHit = 0
local HoldingBlock = false
local Enable = true
local Check = 0 -- combo, left or right, 0 right/1 left
local Damage = 10
local Cooldown = 0.4
local PunchRightEvent = script.Parent.Combo.PunchRight
local PunchLeftEvent = script.Parent.Combo.PunchLeft
local KickLeftEvent = script.Parent.Combo.KickLeft
local PunchSpeed = 2
local SetValue = game:GetService("ReplicatedStorage"):WaitForChild("SetValue")
local HasStunnedAttribute = false
task.spawn(function()
while task.wait(1) do
if tick() - timeSinceLastHit >= 1 then --check if 3 seconds have elapsed since last hit
Check = 0 --reset combo back to 0
end
end
end)
local function hasProperty(object, prop)
local t = object[prop] --this is just done to check if the property existed, if it did nothing would happen, if it didn't an error will pop, the object[prop] is a different way of writing object.prop, (object.Transparency or object["Transparency"])
end
---------------------------------------------------====================
local camera = workspace.CurrentCamera
local CameraShakeEvent = Tool:WaitForChild("Events").CameraShake
local CameraShakeModule = require(game.ReplicatedStorage.CameraShaker)
local function ShakeCamera(shakeCf)
-- shakeCf: CFrame value that represents the offset to apply for shake effect.
-- Apply the effect:
camera.CFrame = camera.CFrame * shakeCf
end
-- Create CameraShaker instance:
local renderPriority = Enum.RenderPriority.Camera.Value + 1
local camShake = CameraShakeModule.new(renderPriority, ShakeCamera)
camShake:Start()
CameraShakeEvent.OnClientEvent:Connect(function()
camShake:ShakeOnce(2, 4, 0.2,0.3)
end)
------------------------===========================================
UserInputService.InputBegan:Connect(function(input, GameProcessed)
if script.Parent.Parent:GetAttribute("Stunned") == true then print("found stun") return end
if not GameProcessed and Humanoid.WalkSpeed < 25 then
if Tool.Parent == Character then
print("tool is in character")
if input.KeyCode == Enum.KeyCode.F then
print('is pressing f')
HoldingBlock = true
Humanoid.WalkSpeed = 8
local BlockAnimationLoader = Humanoid:LoadAnimation(AnimationsFolder.Blocking)
BlockAnimationLoader:Play()
SetValue:FireServer("Block", true)
repeat
wait()
until HoldingBlock == false
BlockAnimationLoader:Stop()
end
end
end
end)
UserInputService.InputEnded:Connect(function(input, GameProcessed)
if not GameProcessed and Humanoid.WalkSpeed < 25 then
if Tool.Parent == Character then
if input.KeyCode == Enum.KeyCode.F then
HoldingBlock = false
Humanoid.WalkSpeed = 16
SetValue:FireServer("Block", false)
end
elseif HoldingBlock == true then
if input.KeyCode == Enum.KeyCode.F then
HoldingBlock = false
Humanoid.WalkSpeed = 16
SetValue:FireServer("Block", false)
end
end
end
end)
the script was also in a tool
Thank you for reading this, hope you can help me somehow