This is what I have in the classic paintball gun, from line 29 in 'Paintball'
if humanoid ~= nil or localplayer then tagHumanoid(humanoid) humanoid:TakeDamage(damage) wait(1) untagHumanoid(humanoid) end
The entire script:
ball = script.Parent damage = 50 function onTouched(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if hit:getMass() < .5 * 200 then hit.BrickColor = ball.BrickColor end for i=1, 1 do local s = Instance.new("Part") s.Shape = 1 s.formFactor = 2 s.Size = Vector3.new(1,.4,1) s.BrickColor = ball.BrickColor local v = Vector3.new(math.random9(-1,1), math.random(0,1), math.random(1,1)) s.Velocity = 15 * v s.CFrame = CFrame.new(ball.Position + v, v) ball.BrickCleanup:clone().Parent = s s.BrickCleanup.Disabled = false s.Parent = game.Workspace end if humanoid ~= nil then tagHumanoid(humanoid) humanoid:TakeDamage(damage) wait(1) untagHumanoid(humanoid) end connection:Disconnect() ball.Parent = nil end function tagHumanoid(humanoid) local tag = ball:FindFirstChild("creator") if tag ~= nil then local new_tag = tag.clone() end end function untagHumanoid(humanoid) if humanoid ~= nil then local tag = humanoid:FindFirstChild("humanoid") if tag ~= nil then tag.Parent = nil end end end connection = ball.Touched:connect(onTouched) wait(3) ball.Parent = nil
The server has no 'Local Player'. It's only achievable inside a local script because local scripts run on the clients' computer, rather than a server script, which only runs on the server and has no relations with any of the clients therefore local player doesn't exist on the server.
However, there are other ways of getting the player on the server, if you're using events such as a Touched event which returns the part that came into contact with the given part, you can then find the player by using the Players:GetPlayerFromCharacter()
function and include the parent of the part that was returned. If it was a character's body part that was returned, then the parent of that part would be the character.
Please accept answers so we know if you've found help.
@xInfinityBear provided you an excellent answer.