I am trying to make it so when a ball is spawned it is half transparent to everyone else but 0% transparent the the person who spawned the ball, I keep getting an error the that ball parameter is getting received as nil. Does anyone know what is wrong?
Server Script:
-- Get necessary services
local TweenService = game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerStorage = game:GetService("ServerStorage")
local Workspace = game:GetService("Workspace")
-- Define tween properties
local tweenGoal = {Size = UDim2.new(1, 0, 0.525, 0)}
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, true)
-- Retrieve all box objects and pop sounds
local boxes = Workspace.Boxes:GetChildren()
local tweens = {}
-- Create tweens for each box
for _, box in ipairs(boxes) do
tweens[box.Name] = TweenService:Create(box.SurfaceGui.Frame.TextLabel, tweenInfo, tweenGoal)
end
-- Function to handle ball drop
ReplicatedStorage.ClientToServerEvents.DropBall.OnServerEvent:Connect(function(player)
local touchDebounce = false
local randomOffset = math.random(-50000000, 50000000) / 1000000000
-- Ensure randomOffset is not zero
while randomOffset == 0 do
randomOffset = math.random(-50000000, 50000000) / 1000000000
end
-- Clone the ball and set its position
local ball = ServerStorage.Ball:Clone()
ball.CFrame = ball.CFrame + Vector3.new(randomOffset, 0, 0)
ball.Parent = Workspace.Balls
ball.Transparency = 0.5
game.ReplicatedStorage.ServerToClientEvents.DropBallSpawnClient:FireClient(player, ball)
-- Ball touches box event
ball.Touched:Connect(function(hit)
if touchDebounce == false and tweens[hit.Name] then
touchDebounce = true
game.ReplicatedStorage.ServerToClientEvents.DropBallDestroyClient:FireClient(player, hit, tweens)
ball:Destroy()
end
end)
end)
Client Script:
-- Client script to handle server events
game.ReplicatedStorage.ServerToClientEvents.DropBallSpawnClient.OnClientEvent:Connect(function(ball)
ball.Transparency = 0
end)
game.ReplicatedStorage.ServerToClientEvents.DropBallDestroyClient.OnClientEvent:Connect(function(hit, tweens)
if tweens[hit.Name] then
tweens[hit.Name]:Play()
end
for _, v in pairs(hit:GetChildren()) do
if v:IsA("ParticleEmitter") then
v:Emit(50)
end
end
local sounds = script.Parent.PopSounds:GetChildren()
local soundIndex = tonumber(hit.Name)
if soundIndex and sounds[soundIndex] then
sounds[soundIndex]:Play()
end
end)

