I’m wanting the orangeHitBox and blueHitBox to no be a variable because I have a lot of them on different maps. So I am trying to get them when they are touched like
local part = script.Parent
local function onHitOrange(hit)
if hit.Name == "OrangeHitBox" then
part:Destroy()
end
end
This is an example but I don’t know how to change the script below to make the orangeHitBox and blueHitBox to no be a variable because I have a lot of them on different maps. Can someone help me?
-- SERVER SCRIPT LOCATED IN BALL
-- <<VERIABLE>
local Players = game:GetService("Players")
local Ball = script.Parent
local orangeHitBox = workspace.Maps.Arena.HitBoxs.GoalO
local blueHitBox = workspace.Maps.Arena.HitBoxs.GoalB
local BallSpawn = workspace.TargetA
local particleO = orangeHitBox.Attachment.ParticleEmitter
local particleB = blueHitBox.Attachment.ParticleEmitter
local orangeTeamGoalValue = workspace.Status.OrangeTeamGoals
local blueTeamGoalValue = workspace.Status.BlueTeamGoals
-- <<FUNCTIONS>>
-- Function to handle scoring
local function score(goal)
print(goal.Name .. " scored a point!")
end
-- Function to handle player hit
local function playerHit(player, hitPart)
print(player.Name)
end
-- Connect functions to events
Ball.Touched:Connect(function(hit)
local character = hit.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
if humanoid then
local player = Players:GetPlayerFromCharacter(character)
playerHit(player, hit)
end
end)
-- Function to reset the ball's position
local function resetBallPosition()
if Ball then
bladeBall:Destroy()
wait(3)
local Ball = game.ServerStorage.Ball:Clone()
Ball.Parent = workspace
Ball.Position = BallSpawn.Position
end
end
-- Function to make a particle effect for PartO
local function createParticleO()
particleO:Clear()
particleO:Emit(1)
script.Parent.Sound:Play()
blueTeamGoalValue.Value += 1
end
-- Function to make a particle effect for PartB
local function createParticleB()
particleB:Clear()
particleB:Emit(1)
script.Parent.Sound:Play()
orangeTeamGoalValue.Value += 1
end
-- Ball touch events
while wait(0.1) do
-- Function to get touching parts for a given hitbox
local function GetTouchingParts(part)
local connection = Ball.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local resultsO = GetTouchingParts(orangeHitBox)
local resultsB = GetTouchingParts(blueHitBox)
-- Check for interactions with onangeHitBox
for i, v in pairs(resultsO) do
if v == Ball then
createParticleO()
score(orangeHitBox)
resetBallPosition()
end
end
-- Check for interactions with blueHitBox
for i, v in pairs(resultsB) do
if v == Ball then
createParticleB()
score(blueHitBox)
resetBallPosition()
end
end
end