When I test this when starting a server, it doesnt seem to work. I have NO clue why...
Here's how it works, in starter GUI there is a local script called "Gun" that creates a part, makes workspace its parent, and places the raycasting script (Which does damage) in the part. Keep in mind, "Gun" is a Local Script, and the raycasting script inside called "Raycast" is a normal script.
I TRIED USING A LOCAL SCRIPT, STILL DOESNT WORK. THE SCRIPT IS FULLY FUNCTIONAL
Here's the script:
local User local Bullet = script.Parent local LastPos = Bullet.Position local RS = game:GetService("RunService").RenderStepped while true do local NewRay = Ray.new(LastPos, Bullet.Position - LastPos) --This casts a ray from the LastPos to the Bullet's current position local H, P = game.Workspace:FindPartOnRay(NewRay, User) local Human = H and H.Parent and H.Parent:FindFirstChild("Humanoid") if Human then local vPlayer = script.Parent.Owner.Value local creator_tag = Instance.new("ObjectValue") creator_tag.Value = vPlayer creator_tag.Name = "creator" creator_tag.Parent = script.Parent tagHumanoid(Human) Human:TakeDamage(10) print("Hit") untagHumanoid(Human) script:Destroy() end LastPos = Bullet.Position --This resets the LastPos to the bullet's current position RS:wait() --This waits for the RenderStepped event to fire, which is once every 1/60th of a second end function tagHumanoid(humanoid) -- todo: make tag expire local tag = script.Parent:findFirstChild("creator") if tag ~= nil then local new_tag = tag:clone() new_tag.Parent = humanoid end end function untagHumanoid(humanoid) if humanoid ~= nil then local tag = humanoid:findFirstChild("creator") if tag ~= nil then tag.Parent = nil end end end
I don't quite understand what you're trying to accomplish here.. Yes, presumedly you're trying to make a gun. But you're creating a part named gun into the Workspace and cloning the raycasting script into it? At the moment its just a brick in workspace raycasting in specified directions...
Also you're defining functions that you call in your While loop on line 6, post to having called them, in the loop.
If you're attempting to make a gun then just make a tool, and have the raycast script inside the tool but as a LocalScript, with Equipped, and Button1Down events.