As the title implies, I’m trying to send over the existence of a part to a script, to create a tool which explodes the user upon contact, but, I am unsure as to what I can send through to make this work. I’ve attempted to send it through by putting "script.Parent.Part into the parenthesis, but to no avail
I am trying to create a tool which explodes a user on contact
Serverscript
function Explode(player, position)
local attachment = Instance.new("Attachment")
local partToTouch = position
attachment.Position = partToTouch.Position
attachment.Parent = workspace.Terrain
local hit = {}
for _,v in pairs(workspace:GetChildren()) do
if v:IsA("Model") and v:FindFirstChildOfClass("Humanoid") then
if (v.Position-attachment.Position).Magnitude < explosionRange and not hit[v] then
hit[v] = true
v:FindFirstChildOfClass("Humanoid"):TakeDamage(explosionDamage)
--knockback
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(15000,15000,15000)
bv.Velocity = (v.Position-attachment.Position).Unit*30+Vector3.new(0,math.random(10,15),0)
bv.Parent = v
game.Debris:AddItem(bv,.5)
end
end
end
attachment:Destroy()
end
partToTouch.Touched:Connect(function(touched)--touched
if touched and touched.Parent then
if touched.Parent:FindFirstChildOfClass("Humanoid") and touched.Parent:FindFirstChild("HumanoidRootPart") then --if it contains the basics of a player
Explode()
partToTouch:Destroy()
end
end
end)
explosionEvent.OnServerEvent:Connect(Explode)
Localscript
local tool = script.Parent
local partTouched
local replicateStorage = game:GetService("ReplicatedStorage")
local explosionEvent = replicateStorage:WaitForChild("ExplosionEvent")
tool.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
explosionEvent:FireServer(script.Parent.Part)
end)
end)