ok, so I have a tool that makes an instance spawn. the new instance has a code which then damages all players who touch it. but that's the problem, since it spawns at the position of the player... I think you get the point.
local tool = script.Parent local mouse local debounce = false local dmg = --set damage here tool.Equipped:Connect(function(m) mouse = m end) tool.Activated:Connect(function() if mouse then local Part = Instance.new("Part",workspace) Part.Position = script.parent.Handle.Position Part.Material = Enum.Material.Neon Part.Size = Vector3.new(0.5,0.5,0.5) Part.CanCollide = false Part.Anchored = true Part.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") if h then debounce = true h:TakeDamage(dmg) wait(1) end debounce = false end) end end)
I know I've been asking a lot of questions here but I just cant find the answer... it would also be appreciated if you could put the link to teach me about this kind of stuff. like in here: https://developer.roblox.com
So I fixed it:
local tool = script.Parent local mouse local debounce = false local dmg = --set damage here local player tool.Equipped:Connect(function(m) mouse = m player = game.Players:GetPlayerFromCharacter(tool.Parent) end) tool.Activated:Connect(function() if mouse then local Part = Instance.new("Part",workspace) Part.Position = script.parent.Handle.Position Part.Material = Enum.Material.Neon Part.Size = Vector3.new(0.5,0.5,0.5) Part.CanCollide = false Part.Anchored = true Part.Touched:Connect(function(hit) local h = hit.Parent:FindFirstChild("Humanoid") local playerName = player.Name if h and not tool.Parent.Name ~= playerName then then debounce = true h:TakeDamage(dmg) wait(1) end debounce = false end) end end)
What I did here, was getting the player using :GetPlayerFromCharacter
on tool.Parent
.
Whenever the Instance is hit, it will check if the hit name is not equal to the player name.
I wasn't able to test it right now, but I hope it helped! You can always put down a comment if it didn't work.