How do I made this Ultra Instinct Auto Dodge work?

Hey so im trying to make a dodge technique for my game much similar to the dodge Goku does in Dragon Ball Super when he goes to his Ultra Instinct form. But currently, Im having some trouble on making it work, can anyone help? Here’s the code vvv

local RP = game:GetService("ReplicatedStorage")
local RF = game:GetService("ReplicatedFirst")
local TS = game:GetService("TweenService")

local Camera = workspace.CurrentCamera

local AnimsFolder = RF.Assets.Animations.Reflexes
local EffectsFolder = RF.Assets.Effects

local Modules = RP.Modules
local StunModule = require(Modules.Combat.TomatoStun)
local HitboxModule = require(Modules.Combat.TomatoHitbox)
local SlowModule = require(Modules.Combat.TomatoSlow)
local CameraShaker = require(Modules.CameraShaker)

local Remote = RP.Remotes.Skills.Eye_Lasers

local module = {}

function module.Activate(player)
	local character = player.Character
	local hrp = character:WaitForChild("HumanoidRootPart")
	local hum = character:WaitForChild("Humanoid")
	local animator = hum:WaitForChild("Animator")

	local Stunned = character:GetAttribute("Stunned")
	local Blocking = character:GetAttribute("Blocking")
	local Attacking = character:GetAttribute("Attacking")
	local UsingSkill = character:GetAttribute("UsingSkill")

	if Stunned or Blocking or Attacking or UsingSkill then
		Remote:FireClient(player,"Timeout")
		return
	end
	character:SetAttribute("UsingSkill",true)
	character:SetAttribute("Dodging",true)

	local Anim1 = AnimsFolder.Dodge1
	local Anim2 = AnimsFolder.Dodge2
	local Anim3 = AnimsFolder.Dodge3
	local Anim4 = AnimsFolder.Dodge4
	
	local currentAnim = math.random(1,4)
	
	local currentHealth = hum.Health
	
	print("CurrentlyDodging")
	
	while character:GetAttribute("Dodging",true) do
		for i, v in pairs(character:GetChildren()) do
			if v:IsA("Part") then
				v.Touched:Connect(function(hit)
					if currentAnim == 1 then
						animator:LoadAnimation(Anim1)
						task.wait(0.1)
					elseif currentAnim == 2 then
						animator:LoadAnimation(Anim2)
						task.wait(0.1)
					elseif currentAnim == 3 then
						animator:LoadAnimation(Anim3)
						task.wait(0.1)
					elseif currentAnim == 4 then
						animator:LoadAnimation(Anim4)
						task.wait(0.1)
					end
					hum.Health = currentHealth
				end)
			end
		end
		print("Dodged")
		task.wait()
	end
end

return module

What should I do?

1 Like

What exactly is wrong with it? All you have said is that you cannot make it work.

Exactly its not working as intended therefore i need help

What is the script meant to do, and what is happening instead?

Well assuming you cant read, It is suppose to detect an incoming hitbox. When it does, it is suppose to make the character play 1 out of the 4 animations given making it look like it is dodging the incoming attack while making the damage that was supposed to be for the player nil.

So what is it doing instead? Playing the wrong animation? Ya might need to add a video for more context

wild

Ahh yes forgot to leave that part out, to be blunt, it isn’t playing the animation 1 of the 4 animations

This would not make the player invulnerable if they take too much damage too quickly. If you handle damage using Humanoid:TakeDamage(), then you could insert a forcefield with .Visibility set to false to make the player invulnerable, just remember to remove it afterwards.

Ahhh I see. Could you give me a demonstration with a script?

Move this line to be at the start of the .Touched function so it chooses a random number every time it is fired. Currently, it chooses one random number at the start, then uses that one number for the rest of the script.

-- enable forcefield

local forceField = Instance.new("ForceField")
forceField.Visible = false
forceField.Parent = character

-- disable forcefield

local forceField = character:FindFirstChildOfClass("ForceField")
if forceField then
	forceField:Destroy()
end

Okay thanks! Last thing is, I’m still having a bit of trouble with the animation. Is there a way i can fix this? Perhaps doing it in a while do loop wasn’t a good idea.

That is correct, a while loop would not be a good fit for this scenario. I assume you want the dodge animation to play whenever the person is attacked. Personally, I would do this by creating a function that is used in place of Humanoid:TakeDamage() to allow for additional checks to be made whenever something tries to deal damage to a humanoid. For example,

function DealDamage(humanoid)
	if humanoid.Parent:GetAttribute("Dodging") then
		-- Play a dodge animation
	else
		humanoid:TakeDamage(amount)
	end
end

This would best be stored in a module script so you can easily call it in any script that tries to deal damage to the player.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.