My Code Doesn't work but it doesn't show any errors

I am making a game about finding items that spawn randomly,
But the grab script doesnt work
The spawner script runs locally
image
And the “FoundScript” Just doesn’t work,
I wanted making the particles client and server

LOCAL SCRIPT

Local Script
local ItemsFolder = game.ReplicatedStorage:WaitForChild("ItemsToBeFound")

local Apples = ItemsFolder.Apple:Clone()

local Banana = ItemsFolder.Banana:Clone()

local BloxyCola = ItemsFolder.BloxyCola:Clone()

Apples.Parent = workspace

Banana.Parent = workspace

BloxyCola.Parent = workspace

local ItemsCords = game.ReplicatedStorage:WaitForChild("RandomItemCoordinates")

local TheRandomNumber = math.random(1,7)

if TheRandomNumber == 1 then

Apples.Position = ItemsCords.RandomItem1.Value

end

if TheRandomNumber == 2 then

Apples.Position = ItemsCords.RandomItem2.Value

end

if TheRandomNumber == 3 then

Apples.Position = ItemsCords.RandomItem3.Value

end

if TheRandomNumber == 4 then

Apples.Position = ItemsCords.RandomItem4.Value

end

if TheRandomNumber == 5 then

Apples.Position = ItemsCords.RandomItem5.Value

end

if TheRandomNumber == 6 then

Apples.Position = ItemsCords.RandomItem6.Value

end

if TheRandomNumber == 7 then

Apples.Position = ItemsCords.RandomItem7.Value

end

local TheRandomNumber2 = math.random(1,7)

if TheRandomNumber2 == 1 then

Banana.Position = ItemsCords.RandomItem1.Value

end

if TheRandomNumber2 == 2 then

Banana.Position = ItemsCords.RandomItem2.Value

end

if TheRandomNumber2 == 3 then

Banana.Position = ItemsCords.RandomItem3.Value

end

if TheRandomNumber2 == 4 then

Banana.Position = ItemsCords.RandomItem4.Value

end

if TheRandomNumber2 == 5 then

Banana.Position = ItemsCords.RandomItem5.Value

end

if TheRandomNumber2 == 6 then

Banana.Position = ItemsCords.RandomItem6.Value

end

if TheRandomNumber2 == 7 then

Banana.Position = ItemsCords.RandomItem7.Value

end

local TheRandomNumber3 = math.random(1,7)

if TheRandomNumber3 == 1 then

BloxyCola.Position = ItemsCords.RandomItem1.Value

end

if TheRandomNumber3 == 2 then

BloxyCola.Position = ItemsCords.RandomItem2.Value

end

if TheRandomNumber3 == 3 then

BloxyCola.Position = ItemsCords.RandomItem3.Value

end

if TheRandomNumber3 == 4 then

BloxyCola.Position = ItemsCords.RandomItem4.Value

end

if TheRandomNumber == 5 then

BloxyCola.Position = ItemsCords.RandomItem5.Value

end

if TheRandomNumber == 6 then

BloxyCola.Position = ItemsCords.RandomItem6.Value

end

if TheRandomNumber == 7 then

BloxyCola.Position = ItemsCords.RandomItem7.Value

end

^^ ITEM SPAWNER ^^

FOUND SCRIPT ( SAME FOR ALL ITEMS)

Script(ServerSide)
local Sound = game.Workspace:WaitForChild("Sounds").FoundItemSFX

local IsBeingTouched = false

local StunHandler = require(game.ReplicatedStorage.StunHandlerV2)

local Debris =  game:GetService("Debris")

script.Parent.Touched:Connect(function(hit)
	
	if hit.Parent:WaitForChild("Humanoid") and IsBeingTouched == false then
		local Humanoid = hit.Parent:WaitForChild("Humanoid") -- Humanoid
		local HumanoidRootPart = hit.Parent:WaitForChild("HumanoidRootPart") -- Getting the main part
		
		
		IsBeingTouched = true --Its being touched, Like a debounce
		
		script.Parent:Destroy() -- Destroy the part
		
		local Particle = game.ServerStorage:WaitForChild("FoundItemParticle"):Clone()
		Particle.Parent = workspace
		Particle.CanCollide = false
		Particle.Anchored = true
		
	--^^ Cloning the part and making it to parent to workspace^^--
		
		Debris:AddItem(Particle,1.621) -- The sound has exactly that amount of time
		
		
		Particle.CFrame = HumanoidRootPart.CFrame
		--^^ Putting the Particle part the same pos as the humanoidrootpart^^--
		
		
		StunHandler.Stun(Humanoid,1.621)
		--Stun So the Player can't move while on the animation--
		
		wait(1.622)
		IsBeingTouched = false
	end
end)

Gyazo Gif link, caution with sound its really bassbosted
https://gyazo.com/6068ec7d5c19f1349e8cc79d9b086ba8

1 Like

You can use Breakpoints or place tons of print()'s to each line to find last line that your code reaches.

I am using both way to find which line causes to problem when i don’t get console errors.

After finding the line that causes to error (most likely a wrong if statement) you can debug it with your own.

the issue is that you’re using a local script to clone a server script
you should adjust this so that the .Touched and everything else is in a local script

The other people got the solutions, but I see you put a script in every single Apple. You can just make a .ChildAdded function to see if it’s named “Apple” and then paste the .Touched code.