Concept of the game: Bet cash on a ball and you can win or lose, only issue is that the ball doesn’t destroy on touch and I have no clue why.
They are inside ReplicatedStorage, 1 ball gets cloned when the spawn ball button is pressed
Which is then the partner is changed to workspace.Plinko.Balls
script.Parent.Touched:Connect(function(h)
if h:IsA("Part") and h.Name == "PlinkoBall" then
print('0.5x Triggered')
wait(0.2)
h:Destroy()
end
end)
Script inside the detector part (client script)
--// Spawn Ball Section
local cash = game.Players.LocalPlayer.leaderstats.Cash.Value
function SpawnBall()
if bet == 0 then
else
if game.Players.LocalPlayer.leaderstats.Cash.Value >= bet then
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - bet
local RS = game:GetService("ReplicatedStorage")
local BallList = RS:WaitForChild("PlinkoBalls")
local Balls = BallList:GetChildren()
local items = BallList:GetChildren()
local randomBall = items[math.random(1, #items)]
print("Plink Ball Purchased")
local ballCopy = randomBall:Clone()
for i = 1, #Balls do
ballCopy.Parent = game.Workspace.Plinko.Balls
ballCopy.Name = "PlinkoBall"
ballCopy.Value.Value = bet
end
end
end
end
script.Parent.MouseButton1Click:Connect(SpawnBall)
Script inside the Spawn Ball button which clones and manages the balls (local script)
add some prints here, the cloning script is ok, but something is off
script.Parent.Touched:Connect(function(h)
print(h)
print"Test 1"
if h:IsA("Part") and h.Name == "PlinkoBall" then
print('0.5x Triggered') -- is this even printing?
wait(0.2)
h:Destroy()
end
end)
SERVER script, that’s why, if you r using local script to CLONE something, you need to put the destroy function locally, change it and say what happens
try this, hope it works, delete that 0.5x script you made, and stay only with the one that clone balls
--// Spawn Ball Section
local cash = game.Players.LocalPlayer.leaderstats.Cash.Value
local CloneDestroyer = game.Workspace.Destination here -- change this to where your 0.5x PART is allocated, to make it work
local P = nil -- variable to prevent lag spamming creation of infinite functions, if you do not disconnect them it will cause some perfomance issues,
function SpawnBall()
if bet == 0 then
else
if game.Players.LocalPlayer.leaderstats.Cash.Value >= bet then
game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - bet
local RS = game:GetService("ReplicatedStorage")
local BallList = RS:WaitForChild("PlinkoBalls")
local Balls = BallList:GetChildren()
local items = BallList:GetChildren()
local randomBall = items[math.random(1, #items)]
print("Plink Ball Purchased")
local ballCopy = randomBall:Clone()
for i = 1, #Balls do
ballCopy.Parent = game.Workspace.Plinko.Balls
ballCopy.Name = "PlinkoBall"
ballCopy.Value.Value = bet
P = ballCopy.Touched:Connect(function(Hit)
-- when this CLONED ball touches the 0.5x Part, it will destroy automatically
if Hit.Parent == CloneDestroyer then -- the "0.5x" part --- this is a variable
print"Hit something"
P:Disconnect() -- kill the function, preventing spam and lag
P = nil -- making it nil again until a new Ball is cloned
ballCopy:Destroy() -- Destroy the cloned ball
return
else
return
end
end
end
end
end
script.Parent.MouseButton1Click:Connect(SpawnBall)