Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is my damage script only damage me but not players that are standing still?

Here is my script:

local Tool = script.Parent
Tool.RemoteEvent.OnServerEvent:Connect(function(player, pos)
	local part = Instance.new("Part")
	part.Parent = Tool
	part.Anchored = true
	part.Transparency = 1
	part.CanCollide = false
	part.Massless = true
	part.Size = Vector3.new(1,1,1)
	part.Position = pos
	local point2 = Instance.new("Attachment")
	point2.Name = ("Ending Point")
	point2.Parent = part
	Tool.Magic.Beam.Attachment1 = point2
	point2.WorldPosition = part.Position
	part.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid")then
			hit.Parent.Humanoid:TakeDamage (20)
			wait(0.05)
			part:Destroy()
		end
	end)
	wait(0.5)
	part:Destroy()
end)

I put this script in a tool, the pos is sent from my local script and it is the mouse.hit.position. My weapon is to create a lazer when clicked. There is no error to the script. When I shoot at a place and then I walk to it, it damages me but when I hit a player that is standing still, it doesn't do any damage. How can I fix this?

2 comments

0

Is it meant to damage others or yourself? Have you tried with multiple players/NPC's?

0

Yes, it is meant to damage others and I have tried it on many NPC but not players

1 answer

It appears to me that you don't check if the player is yourself. Use Players:GetPlayerFromCharacter(hit.Parent) and see if it's the attacking player. If it is, then return nil.

if (Players:GetPlayerFromCharacter(hit.Parent)) then
	return nil;
end

1 comment

0

lol just type if not hit:IsDescendantOf(Character) then

This discussion is preserved as it was. New answers, comments, and votes are closed.