Invincibility stim scripting problem

Hello guys, I recently wanted to create a stim that if you will use, it will give you infinite health, I made and script and animation. Due to my scripting issues aka. I can’t normally script or I can say I don’t even know how to script normally, it doesn’t work and output says nothing about the script, maybe because theres no printing about errors in the code.
The code:

local player = game:GetService("Players").LocalPlayer
local character = player.Character
local hp = player.Character.Humanoid.Health
local animation = script.Parent:FindFirstChild("GDOAnim")
local injectAnimation = character.Humanoid:LoadAnimation(animation)
local inf = 99999999999999999999999999999999999999999999999

local canInject = true

local injection = 100

script.Parent.Activated:Connect(function(onClick)
	if canInject then
		canInject = false
		injectAnimation:Play()
		wait(injection)
		hp = inf
		if player.hp == inf then
			print(player.Name .. ("used GDO-88 successfully."))
		elseif player.hp == 100 then
			print(player.Name .. ("used GDO-88 and failed."))
		end
	end
	
end)

I tried to recreate something from a guide, but it failed. Please help!

2 Likes

You are waiting 100 seconds before setting the player’s health to inf so you’d only see results after that time.

1 Like

Humanoid:LoadAnimation() is deprecated use the animator of the humanoid

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local track = Animator:LoadAnimation(putanimobjecthere)
2 Likes

well um what do i do with this now if it doesnt work, i used roblox animator, not moon or anything else

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local track = Animator:LoadAnimation()
local animation = script.Parent:FindFirstChild("GDOAnim")
local hp = plr.Character.Humanoid.Health
local inf = 99999999999999999999999999999999999999999999999

local canInject = true

local injection = 3
local destroying = 60

script.Parent.Activated:Connect(function(onClick)
	if canInject then
		canInject = false
		animation:Play()
		wait(injection)
		hp = inf
		if plr.hp == inf then
			wait(destroying)
			print(plr.Name .. ("used GDO-88 successfully."))
		elseif plr.hp == 100 then
			print(plr.Name .. ("used GDO-88 and failed."))
		end
	end
	
end)

why do i have so many locals am i so bad

You did that wrong you have to get the animation object and then use Animator:LoadAnimation(anim)

what do you mean i dont understand sorry im dumb

Put these into the script like this:

local Animator = humanoid:WaitForChild("Animator")
local animation = script.Parent:FindFirstChild("GDOAnim")
local track = Animator:LoadAnimation(animation)
local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local animation = script.Parent:FindFirstChild("GDOAnim")
local track = Animator:LoadAnimation(animation)
local hp = plr.Character.Humanoid.Health
local inf = 99999999999999999999999999999999999999999999999

like this?

1 Like

Yes, like that. Is there any other problems with the script.
Also I suggest changing the variable inf to:

local inf = math.huge
1 Like

nothing happens, same with output, absolutely nothing

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local animation = script.Parent:FindFirstChild("GDOAnim")
local track = Animator:LoadAnimation(animation)
local hp = plr.Character.Humanoid.Health
local inf = math.huge

local canInject = true

local injection = 3
local destroying = 60

script.Parent.Activated:Connect(function(onClick)
	if canInject then
		canInject = false
		animation:Play()
		wait(injection)
		hp = inf
		if plr.hp == inf then
			wait(destroying)
			print(plr.Name .. ("used GDO-88 successfully."))
		elseif plr.hp == 100 then
			print(plr.Name .. ("used GDO-88 and failed."))
		end
	end
	
end)
1 Like

You forgot to set canInject back to true or is that how you intended it?
Also why are you checking plr.hp and not hp?
You also need to update the health there
Here’s the fixed script:

local plr = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = plr.Character or plr.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local Animator = humanoid:WaitForChild("Animator")
local animation = script.Parent:FindFirstChild("GDOAnim")
local track = Animator:LoadAnimation(animation)
local hp = plr.Character.Humanoid.Health
local inf = math.huge

local canInject = true

local injection = 3
local destroying = 60

script.Parent.Activated:Connect(function(onClick)
	if canInject then
        hp = humanoid.Health
		canInject = false
		animation:Play()
		wait(injection)
		hp = inf
		if hp == inf then
			wait(destroying)
			print(plr.Name .. ("used GDO-88 successfully."))
		elseif hp == 100 then
			print(plr.Name .. ("used GDO-88 and failed."))
		end
	end
	
end)
1 Like

Well, I don’t know if that doesnt let me inject but I think it dont let me before the animation, etc. But after you use the stim it should disappear until you respawn

1 Like

by the way @hasoco here is the explorer
image
GDOAnim is only infinite keyframes

1 Like

Doesnt work, I tried with replacing canInject = false with animation:Play()

1 Like

Infinite keyframes? You have to convert it to an animation object. Left-click the keyframe object and press “Save to Roblox”

Don’t replace that with that. Just keep it the way it is.