I am currently trying to make a Force Field at the moment and it all works fine, i'm still working on pretty much everything about this, but there is one thing that is stumping me. I can't get my force field to affect other people but not me. Basically, if anybody touches the forcefield, or goes inside of it, they take damage, but if i touch it, i don't want to take damage. I'm not too familiar with local players as apposed to any other character. The function of the hitting a character is at the bottom of the code. I tried to make a little bit of code, but i never could quite figure it out, please help me, thanks in advance! :)
local tool = script.Parent Something = not nil local debounce = false local character = game:GetService('Players').LocalPlayer local player = character.Character or character.CharacterAdded:wait() tool.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key == "q" and debounce == false then debounce = true print("ForceField") local ForceField = Instance.new("Part", player) ForceField.BrickColor = BrickColor.new("Deep blue") ForceField.Transparency = 0.7 ForceField.CanCollide = false ForceField.Anchored = true ForceField.Shape = Enum.PartType.Ball ForceField.Size = Vector3.new(25,25,25) ForceField.BottomSurface = Enum.SurfaceType.Smooth ForceField.TopSurface = Enum.SurfaceType.Smooth ForceField.Position = player.Torso.Position ForceField.Parent = game.Workspace ForceField.Touched:connect(function(hit) local anyplayer = game:GetService('Players') local localplayer = if anyplayer then print ("firing") elseif end end) wait(2) ForceField:remove() debounce = false end end) end)
Check
You have your hit
variable, and you can find out if the part belongs to a player using Players:GetPlayerFromCharacter(hit.Parent)
. With this, checking to see if you touched it is trivial.
However, I would recommend checking to see if Hit is a descendant of the Player's Character because that will work better for hats and tools.
part.Touched:connect(function(hit) if not hit:IsDescendantOf(character) then -- If it's not you print("DEATH TO THE HEATHENS") else print("Hi me.") end end)