Make a part made in the server damage everybody except the local player

  1. What do you want to achieve?
    I want to make a tool that when clicked will create a part that looks like lightning and will deal damage to everybody except the person who made that part (The person using the tool) if they touch / make contact with it.

  2. What is the issue?
    Due to the part being made on the server, I couldn’t get the local player to check if the person who touches it is the person who made it or not.

  3. What solutions have you tried so far?
    I have searched to see if there is a way to bring the local player from a local script to a server script but I have been left confused or without an answer. Also some of the methods haven’t worked for me.

Local script: (Inside of a tool which is inside of “StarterPack”)

local repStorage = game:GetService("ReplicatedStorage")

local event = repStorage.LightningEvent

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local toolDeb = false
local CD = 1 --Cooldown

local tool = script.Parent

tool.Activated:Connect(function()
	if not toolDeb then
		toolDeb = true

		local pos = mouse.Hit.Position

		event:FireServer(pos)

		task.wait(CD)
		toolDeb = false
	end
end)

Server script: (Inside of “ServerScriptService”)

local repStorage = game:GetService("ReplicatedStorage")
local debris = game:GetService("Debris")

local event = repStorage.LightningEvent

event.OnServerEvent:Connect(function(player, pos)
	local humanoid = player.Character:WaitForChild("Humanoid")

	local part = Instance.new("Part", workspace)
	part.BrickColor = BrickColor.new("New Yeller")
	part.Material = Enum.Material.Neon
	part.Transparency = 0.2
	part.Anchored = true
	part.CanCollide = false
	part.CastShadow = false

	part.Position = pos
	part.Size = Vector3.new(2, 200, 2)

	debris:AddItem(part, 1.2)
end)

All help is appreciated! Thanks in advance.

-Kotium

2 Likes

You woule be best to scan the players and filter them to only be people that arent you and add them to a table then scan the workspace for players in that table and lower their health

I can provide an example in a few hours if you dont understand

2 Likes

I’ll try this and let you know if it works or not. thanks!

1 Like

I accidentally found a way easier solution lol. For some odd reason, I was using a normal part that didnt have any properties except the parent and position and it was killing me for no reason when I clicked so I tried something else but now using the same script as before but this time more properties it works. anyways thanks for the help!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.