-
What do you want to achieve? Honestly the main thing I want to do is just make my character take no damage when they reach a certain hp number (basically shows they are “knocked”). My way of working around this (because I saw it was impossible to do that (have a humanoid take no damage) from a similar post on dev forums) was using a forcefield but the forcefield doesn’t work.
-
What is the issue? As I previously stated, the forcefield doesn’t work or do the job of preventing damage. I included a video for you which goes over the code at the end which you probably don’t need to see because I pasted it in here.
Dropbox - Health.rbxl - Roblox Studio.mp4 - Simplify your life -
What solutions have you tried so far? Quite frankly I am so confused because isn’t a forcefield supposed to prevent damage to the humanoid according to the documentation on it? I tried many things such as adding in an if statement and a damage variable but to no avail. I previously even had a zombie spawner model but figured it took damage by taking away from my health explaining why the forcefield wasn’t working but I guess I was wrong.
-- Quick kill script I made in workspace --
local part = script.Parent
local db = true
part.Touched:Connect(function(otherpart, damage)
local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
if humanoid then
if not otherpart.Parent:FindFirstChild("force") and db == true then
db = false
humanoid:TakeDamage(5)
task.wait(0.5)
db = true
end
end
end)
-- Server Script in ScriptService --
local rs = game:GetService("ReplicatedStorage")
local peel = rs.peel
local function fuse(player, charac, humanoid)
local animateScript = charac:WaitForChild("Animate")
local animation1 = animateScript.idle:WaitForChild("Animation1")
animation1.AnimationId = "rbxassetid://14237514199"
local animation2 = animateScript.idle:WaitForChild("Animation2")
animation2.AnimationId = "rbxassetid://14237514199"
humanoid.WalkSpeed = 0.5
humanoid.JumpPower = 0
humanoid.AutoRotate = false
end
peel.OnServerEvent:Connect(fuse)
-- Local Script in ScreenGUI --
local rs = game:GetService("ReplicatedStorage")
local peel = rs.peel
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hum = character:WaitForChild("Humanoid")
local function giveForcefield()
local forceField = Instance.new("ForceField")
forceField.Visible = true
forceField.Parent = character
end
hum.HealthChanged:Connect(function(health)
if health <= 80 then
local forceField = Instance.new("ForceField")
forceField.Name = "force"
forceField.Visible = true
forceField.Parent = character
peel:FireServer(character, hum)
end
local screenui = script.Parent
local hpbar = screenui.Frame.hpbar
local hp = health / hum.MaxHealth
hpbar:TweenSize(UDim2.new(hp,0,1,0), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 0.5)
task.wait(0.1)
end)
Thank you for the help in advance!