I was working on a blocking script and I was doing the checkIfPlayerIsBlocking. If true, then damage gets set to 5. If not, 10. Problem is, it says blocking isn’t a member of character. In the local script, I made a bool value called blocking, and set its parent to chartacer. I don’t know why it isn’t working. Any help is apprecitaed. Thanks!
Server script:
--Created by RinxfulROBLOX
local meele = script.Parent
local ReplicatedStorage = game.ReplicatedStorage
local meeleEvent = ReplicatedStorage:WaitForChild("MeeleEvent")
local blockEvent = ReplicatedStorage:WaitForChild("BlockEvent")
local equipped = false
local damage = 10 --Damage
local punchtime = 1.5
local lastclick = tick()
local combowindow = 1 --Amount of time you must click on the combo in order for it to progress
local combo = 0
meele.Equipped:connect(function()
equipped = true
combo = 0
lastclick = tick()
character = meele.Parent
player = game.Players:GetPlayerFromCharacter(character)
humanoid = character:WaitForChild("Humanoid")
mouse = player:GetMouse()
end)
meele.Unequipped:connect(function()
equipped = false
character = nil
player = nil
humanoid = nil
end)
meele.Activated:connect(function()
if equipped and player then
local clickdelta = tick() - lastclick --How long did I last click?
if lastclick > punchtime then
lastclick = tick()
if clickdelta < punchtime + combowindow then
combo = (combo + 1) % 3
else
combo = 0
end
if player then
if combo == 0 then
meeleEvent:FireClient(player, "RunAnimation", "combo1")
--You add sounds here, sound:Play()
elseif combo == 1 then
meeleEvent:FireClient(player, "RunAnimation", "combo2")
elseif combo == 2 then
meeleEvent:FireClient(player, "RunAnimation", "combo3")
end
end
end
end
if equipped and player then
local humanoidRootPart = character.HumanoidRootPart
for i,player in pairs(game.Workspace:GetChildren("Model")) do --Get all models and checks if they have humanoid in it
if player:IsA("Model") and player.Humanoid and player.HumanoidRootPart then
if (player.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude < 5 then--Magnitude
if player and player ~= character then -- Dot Product
local playerToHeadVector = (character.HumanoidRootPart.Position - player.HumanoidRootPart.Position).Unit
local ourLookVector = character.Head.CFrame.LookVector
local DotProduct = playerToHeadVector:Dot(ourLookVector)--Dot product so player won't hit while looking behind
if DotProduct <= 0.5 then
print("True")
player.Humanoid:TakeDamage(damage * combo)
wait(0.45)
if (player.HumanoidRootPart.Position - character.HumanoidRootPart.Position).Magnitude < 2 then
player.Humanoid:TakeDamage(damage * combo) --Checking if player magnitude is still there
end
end
end
end
end
end
end
end)
function checkIfPlayerIsBlocking()
if equipped then
if character.Blocking then
local blocking = player.Character.Blocking
if blocking.Value == true then
damage = 5
else
damage = 10
end
end
end
end
blockEvent.OnServerEvent:connect(checkIfPlayerIsBlocking)
local script:
--Blocking Script made by RinxfulROBLOX--
local ReplicatedStorage = game.ReplicatedStorage
local blockEvent = ReplicatedStorage.BlockEvent
local UserInputService = game:GetService("UserInputService")
local Blocking = Instance.new("BoolValue")--Setting BoolValue so when player presses F, blocking will be set to true
Blocking.Name = "Blocking"
Blocking.Value = false --Playing isn't blocking as of now
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local humanoid = character:WaitForChild("Humanoid")
local blockSpeed = 8
local originlSpeed = humanoid.WalkSpeed
local meele = script.Parent
local equipped = false --Player won't be able to block if they don't have meele, or anytype of fighting style equipped
meele.Equipped:connect(function()
equipped = true
print(equipped)
Blocking.Value = false
print(Blocking.Value)
if equipped then
print("Equipped")
end
end)
meele.Unequipped:connect(function()
equipped = false
print(equipped)
Blocking.Value = false
print(Blocking.Value)
if not equipped then
print("Not Equipped")
end
end)
Blocking.Parent = character --For me it makes it way eaiser to do this to communicate with the server
print(Blocking.Value)
local BlockingKeyCode = Enum.KeyCode.R
local BlockAnim = meele.BlockAnim
local function blockBegan(inputObject,gameProcessed)
--Checking if player pressed R, and meele is equipped, and they aren't blocking
if inputObject.KeyCode == BlockingKeyCode and equipped and Blocking.Value == false then
print("Blocking..")
Blocking.Value = true
print(Blocking.Value)
if player and humanoid then
loadedBlockAnim = humanoid:LoadAnimation(BlockAnim)
loadedBlockAnim:Play()
humanoid.WalkSpeed = blockSpeed
blockEvent:FireServer()
end
end
end
local function blockEnded(inputObject,gameProcessed)
--Now that player is blocking and blocking is true, we gotta make it so that when they let go of R, blocking is set back to false
if inputObject.KeyCode == BlockingKeyCode and equipped and Blocking.Value == true then
print("Block ended")
Blocking.Value = false
print(Blocking.Value)
humanoid.WalkSpeed = originlSpeed
loadedBlockAnim:Stop()
end
end
UserInputService.InputBegan:connect(blockBegan)
UserInputService.InputEnded:connect(blockEnded)