Part won't destroy on detection


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.
image
They are inside ReplicatedStorage, 1 ball gets cloned when the spawn ball button is pressed
image
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)

2 Likes

I feel like it’s important to say that the balls do destroy on touch when they are just in workspace and aren’t destroyed when cloned.

1 Like

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)
1 Like

It doesn’t seem to print anything when hitting.

1 Like

What if I make this script in reverse where i put the script inside the ball and if it touches the detector then the ball destroys itself

1 Like
script.Parent.Touched:Connect(function(h)
	print(h)
	print"Test 1"
	if h.Parent == "LowRisk" then
print("hit")
	script.Parent:Destroy()
	end
end)

Didn’t work

script.Parent.Touched:Connect(function(h) — what is this reference? can you show me

really weird

Where is this script located? What is script.Parent?

script.Parent is
image

Plinko is a folder in workspace

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

No difference, still doesn’t destroy.

Would you like a copy of the file so you can try it yourself?

i have an idea, brb, i’ll make something here and i’ll send to you

It works when the balls are in workspace to start off instead of copying over and it drives me crazy cause idk why

(the 0.5x didnt work because i named them “Balls” while it was named something else)

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)

There is a bunch of errors inside the script that I’m having trouble fixing
If you can fix it this is the game file
voids gamble game.rbxl (61.0 KB)

lol, ok i’ll check it out xD _______________

now i understand why nothing worked, i’m fixing everything here

Yeah my scripting was messy too, sorry I’m new to scripting :sob:

1 Like