Still taking damage with ForceField

I’m trying to create a bossfight, and I have this ring set up to deal damage. But even though I am using TakeDamage(), when the player has a forcefield they still take damage. I’m not sure what to do right now.

local deb = false

script.Parent.Touched:Connect(function(hit)
	if hit.Parent.Name == "Nedia" or deb == true or hit.Parent:FindFirstChild("ForceField") then
		return
	else
		deb = true
		hit.Parent.Humanoid:TakeDamage(50)
		wait(5)
		deb = false
	end
end)

Why not enable the forcefield when it needs to be activated, then do Humanoid:TakeDamage? That way you don’t need to check for the forcefield.

This is the script in my tool that gives the forcefield, and when the character has the forcefield and you can visually see the forcefield. it still damages them. Also that was what I had done originally and it was still damaging the player.

local ips = game:GetService("UserInputService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humroot = char:WaitForChild("HumanoidRootPart")
local hum = char.Humanoid
local deb = false
local tool = script.Parent

ips.InputBegan:Connect(function(input)
	if tool.Parent.Parent == game.Workspace and input.KeyCode == Enum.KeyCode.X then
		if deb == false then
			local rolling = script.Parent:FindFirstChild("Rolling")
			local anim = script:FindFirstChild("roll")
			local anim2 = hum:LoadAnimation(anim)
			rolling.Value = true
			script.Parent:FindFirstChild("ClickedLol").Value = true
			script.Parent:FindFirstChild("Clicked2").Value = true
			deb = true
			anim2:Play()
			local ff = Instance.new("ForceField",char)
			ff.Parent = char
			wait(2)
			anim2:Stop()
			char.ForceField:Destroy()
			script.Parent:FindFirstChild("Clicked2").Value = false
			rolling.Value = false
			wait(1)
			deb = false
		end
	end
end)

This is a client-server issue. The script you provided inserts the forcefield on the client which the server can’t see. Therefore your server script can’t see the forcefield. Instead, you should create the forcefield on the server using something like remote events.

1 Like

Thank you, I will try something like that now.