With some help from other people, i have been successful in creating a tool that spawns a bubble around your character that damages other people. I'm now getting frustrated when this doesn't work online. It works somewhat, but there is one major flaw in the coding and idk where considering there is no errors. WHenever i put this to online (Or when i launch a server with two players for this matter) the script goes exactly as planned, except when the person dies, if you try to use the tool again, the bubble gets placed near the dead body and not near the actual person if that makes sense. The bubble doesn't want to go to the CFrame of the player's current torso, instead, it goes to the torso of the dead torso and idk why. This only happens when i launch a server or click play.
The scripts being shown is a local script in a tool
local tool = script.Parent local health = false humanoid = 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.CFrame = CFrame.new(player.Torso.Position + Vector3.new(0,0,0)) ForceField.Parent = game.Workspace ForceField.Touched:connect(function(hit) local humanoid = hit.Parent:findFirstChild("Humanoid") if not hit:IsDescendantOf(player) and health == false and humanoid then health = true humanoid.Health = humanoid.Health -3 print ("DEATH TO THE HOOOOMANNSSSS") health = false else print("Hi Me ;)") wait(.1) return end end) wait(2) ForceField:remove() debounce = false end end) end)
Yes, your issue is very very simple. Alright, so what you have done as I saw from the first few lines if your code is:
You defined the Character
outside of the function.
That right there is no good 'cause then you have defined the Character
that was first spawned, not the Character
that gets spawned every time you respawn. If you want to fix this it's simple all you have to do is:
Move the variable for the Character
inside of the function so basically like this...
local character = game.Players.LocalPlayer -- The player tool.Equipped:connect(function(mouse) mouse.KeyDown:connect(function(key) if key == "q" and debounce == false then debounce = true local player = character.Character -- Btw you got it the other way around xD The player is the LocalPlayer and the Character is the Character xD if that makes sense. -- Code end end) end)
The code above defines the Character
every time the function
is ran. Therefore it will define the Character
that is currently the LocalPlayer
. Not the one that died :'c poor Johnny. Ok anyways...
I hope I helped! Thank you for reading this answer. Any other problems? Please post a comment below.
~~ KingLoneCat