Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a player unhittable/godmode for a few seconds?

Asked by 3 years ago
Edited 3 years ago

Alright, so here's a story, I and my friends together decided to make a demon slayer game.(Going quite well ngl) and if you're familiar with Akaza's Compass Needle(basically like ultra instinct or InvincibilityFrame) and I'm having trouble making a script like this, I tried using force field but it would to "weird", I tried using max health script but some moves deal massive damage so it didn't work.

while true do
   script.Parent.MaxHealth = math.huge
   script.Parent.Health = math.huge
   wait()
end ---Something like this

Is there a script that makes your character unhittable?(something that makes other characters that phases thru your body but you're able to hit another player) or makes them godmode(hittable but health doesn't go down) for a few seconds? One of them would be helpful. Would also appreciate if you describe what a line does(I'm also a newbie scripter so just asking someone to give me a script is like hiring a scripter lmao so yeah..)

1 answer

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

You could use ForceField to give player a shield but i am not sure if it fits with the game, it also only works with Humanoid:TakeDamage function so it's not that great.

The better option would be to create an instance of any class and call it GodMode for example and then checking if the Instance is in the character, if it is then you won't damage him.

local function SetGodMode(Character, Duration)

    local GodMode = Instance.new('Configuration')
    GodMode.Name = 'GodMode'
    GodMode.Parent = Character

    delay(Duration, function()

        if (GodMode)
        then
            GodeMode:Destroy()
        end
    end)
end

local function IsGodMode(Character)

    return (Character:FindFirstChild('GodMode') ~= nil)
end

IsGodMode returns if character is in gode mode, you can use it to check if he is in god mode before damaging him. in SetGodMode function it creates new GodMode object and after Duration time it removes it, delay is a function that runs given function after given time in another thread which means it won't stop the thread for the seconds.

Ad

Answer this question