I've Tried looking for tutorials or anything else, No luck, I have a animation for a block but i cant seem to make a blocking script. Can anyone help me?
How to make a Combat Blocking Script?
2 answers
So I was debating whether to answer this now or later, and here I am. Here's how you'll do it:
First off, you want to make sure that the player's character (or player) has a Value called "Blocking". How you can achieve this is by having a Script inside of 'StarterCharacterScripts'. Inside of the script (make sure it is a ServerScript and not a LocalScript), you would do;
wait();
local char = script.Parent;
local h = char:WaitForChilr("Humanoid");
local blocking = Instance.new("BoolValue");
blocking.Name = "Blocking";
blocking.Value = false;
Now that we have a bool set up (this is to protect as much as possible against exploitation), we will need the player to block. You would create a localscript inside of StarterGUI and have this in it:
local blockingKey = Enum.KeyCode.R;
local uis = game:GetService("UserInputService");
local p = game.Players.LocalPlayer;
local c = p.Character or p.CharacterAdded:wait();
local RF = game.ReplicatedStorage.RemoteFunction;
local response;
uis.InputBegan:Connect(function(key, gameProc) -- this is an event that fires when player presses a key
if(key.KeyCode == blockingKey and not gameProc) then
response = RF:InvokeServer(true);
end
end)
uis.InputEnded:Connect(function(key, gameProc) -- this is an event that fires when player lets go after holding a key
if(key.KeyCode == blockingKey and not gameProc) then
response = RF:InvokeServer(false);
end
end)
-- You can now start using 'response' in other functions, within this script.
Now, create a RemoteFunction in ReplicatedStorage. Then, make a script in ServerScriptService, and inside of it, include the following:
local RF = game.ReplicatedStorage.RemoteFunction;
local blockSpeed = 8; -- change this to how slow you want them to go when blocking
RF.OnServerInvoke = function(player, this)
local c = player.Character or player.CharacterAdded:wait();
local blocking = c:FindFirstChild("Blocking");
assert(blocking ~= nil and c ~= nil, "Blocking and/or Character was not found.");
local h = c:FindFirstChildOfClass("Humanoid");
local oldSpeed = h.WalkSpeed;
if(this) then
if not (blocking.Value) then
blocking.Value = true;
h.WalkSpeed = blockSpeed;
-- Load animation and play here
end
elseif this == false then
if (blocking.Value) then
blocking.Value = false;
h.WalkSpeed = oldSpeed;
-- Stop animation here
end
end
end
Now that we have a Blocking system set up, on your hitBox script (that makes players take damage), check if the hit char has a value called "Blocking" and if it's Value is true. If it is, make them take less damage. If it isn't, take normal damage.
That's the way I would do it.
4 comments
I tried Using this, I followed each step. and yet i get this error: ServerScriptService.Blocking Script:7: Blocking and/or Character was not found.
Updated it. Try now.
Any way to make it so you can play a block animation in the script?
Also, No errors but the block doesnt seem to be slowing down the player or reducing any damage it takes.
The blocking method in the old NSUNS3 by Friaza went something like this
hp = Humanoid.Health
while blocking = true do
Humanoid.Health = hp
wait()
end
This method doesn't actually block damage, it just resets any damage that the player has took incredibly quickly, meaning that you if you take a single instance of damage more than your current hp you die anyways.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
This isn't a requesting site...