i need help to improve my dodging script, as everytime i go to a kill brick, it glitches and takes more then one dodges
local humanoid = script.Parent.Humanoid
local dodges = script.Dodges
local cooldown = false
local dodge = script.Dodge
local animater = humanoid:LoadAnimation(dodge)
humanoid.HealthChanged:Connect(function()
if dodges.Value == 0 and not cooldown then
return
elseif not cooldown and dodges.Value > 0 then
local forcefield = Instance.new("ForceField")
cooldown = true
forcefield.Visible = false
forcefield.Parent = script.Parent.HumanoidRootPart
humanoid.MaxHealth = 1000020200000000
humanoid.Health = 1000000000000000
animater:Play()
dodges.Value = dodges.Value - 1
print("Dodged")
forcefield:Destroy()
humanoid.MaxHealth = 1
wait()
cooldown = false
end
end)
23:49:13.309 ▶ Dodged (x5)
2 Likes
also for some reason the health glitches and gets stuck at 100020200
1 Like
Your wait() doesnt have a number, give it a number.
Also wait is decapitated, use task.wait (its wait but better)
1 Like
thanks but theres still a problem, i want to make the player stop losing dodges if hes currently dodging, because of the health:healthchange function, is there any other way?
How does the dodge work? Is it instant or are you invicible for x time, you dont need to set the health of the player when the forcefield is created.
2 Likes
Dodges says 0 on the gui, assuming you have more than 1:
Instead of damaging the player, you should create a module script that damages the player. The module script go through checks, in the specific check it checks if the player has any dodges left.
If there is then it removes a dodge. Else it damages the player.
For the killbrick, i assume you use touched event, touched event is a bit laggy and bad so id prefer if you would have a Debounce for it that lastes like a second or 2
1 Like
oh thats the health, the dodges are actualy 5 but for the last one, for the killbrick, what do you mean debounce?
Debounce is what we like to give our cooldown variable a name, its pretty much the cooldown variable in your script
1 Like
oh ok, i will try adding that, brb
i added a debounce
local function PlayerTouched(Part)
local Parent = Part.Parent
if game.Players:GetPlayerFromCharacter(Parent) and not cooldown then
cooldown = true
Parent.Humanoid.Health = 0
wait()
cooldown = false
end
end
Brick.Touched:connect(PlayerTouched)
including some changes to the dodge script
local humanoid = script.Parent.Humanoid
local dodges = script.Dodges
local cooldown = false
local dodge = script.Dodge
local animater = humanoid:LoadAnimation(dodge)
humanoid.HealthChanged:Connect(function()
if dodges.Value == 0 and not cooldown then
return
elseif not cooldown and dodges.Value > 0 then
local forcefield = Instance.new("ForceField")
cooldown = true
forcefield.Visible = false
forcefield.Parent = script.Parent.HumanoidRootPart
humanoid.Health = humanoid.MaxHealth
animater:Play()
dodges.Value = dodges.Value - 1
print("Dodged")
task.wait(1)
forcefield:Destroy()
cooldown = false
end
end)
but it only made it worse, now instently killing me when ever i touch the kill brick
Brother you didnt add a number to the wait in the killbrick
1 Like
my bad : ), i will fix it real quick, in the mean time, is there anyway to make a player invinsable?
Use a loop on all of the players descendants and make the transparency 1, also
The way youre damaging and dodging is a bad way, before damaging, check if the player has enough dodges instead of setting the health to 0
1 Like