Anyone know how I can fix this issue?

I made a marble script in my game, and so far, I’m facing a major issue with it.

For some reason, as soon as I join the game, and some other times after respawning, when I touch the marble, it doesn’t spawn for some reason, even though CanCollide and CanTouch is on. CanCollide is off sometimes also, but CanTouch is still on, but nothing happens. (This usually happens in the way that I’ve just described it, but also just stops working some time after 2 - 3 people use it.)

How would I fix this?

Server Script In Marble

Marble
--< Remotes
local CreateMarble = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("CreateMarble")
local DeleteMarble = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("DeleteMarble")

local Ball = script.Parent

local cooldown = false

--< Touched event
Ball.Touched:Connect(function(hit)
	if not cooldown then cooldown = true
		if hit.Parent:FindFirstChildOfClass("Humanoid") and not hit.Parent:FindFirstChild("Marble") then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local character = hit.Parent
			CreateMarble:Fire(player, character, Ball)
			
			script.Parent.CanCollide = false
			script.Parent.Transparency = 1

			task.wait(7)
			
			print("cooldown over")
			
			cooldown = false
			
			script.Parent.CanCollide = true
			script.Parent.Transparency = .5
		end
	end
end)
Server Script In ServerScriptService
--< Remotes
local CreateMarble = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("CreateMarble")
local DeleteMarble = game:GetService("ReplicatedStorage"):WaitForChild("Remotes"):WaitForChild("DeleteMarble")

local RainbowParticle = game:GetService("ReplicatedStorage"):WaitForChild("GameAssets"):WaitForChild("Particles"):WaitForChild("Rainbow_Explosion")

function effect(marble)
	local particle = RainbowParticle:Clone()
	particle.Parent = marble

	task.wait(2)

	particle.Enabled = false
	game:GetService("Debris"):AddItem(particle, 12)
end

--< Create a marble for the player
CreateMarble.Event:Connect(function(player, char, ball)
	local root = char:WaitForChild("HumanoidRootPart")
	local marble = Instance.new("Part")
	local currentPlayerPos = root.Position
	print("created")

	marble.Name = "Marble"
	marble.Size = Vector3.new(8,8,8)
	marble.BrickColor = BrickColor.Random()
	marble.Transparency = .5
	marble.Shape = Enum.PartType.Ball
	marble.Parent = char
	marble.Material = Enum.Material.SmoothPlastic

	marble.Position = currentPlayerPos

	local Velocity = Instance.new("BodyAngularVelocity")
	Velocity.Parent = marble
	local Hum = char:WaitForChild("Humanoid")
	local Weld = Instance.new("Weld")
	Weld.Parent = marble
	Weld.Part0 = root
	Weld.Part1 = marble
	Hum.PlatformStand = true
	
	task.spawn(effect, marble)

	while task.wait() do
		if marble and marble.BodyAngularVelocity then
			marble:WaitForChild("BodyAngularVelocity").AngularVelocity = Vector3.new(char.Humanoid.MoveDirection.z * 48, 0, char.Humanoid.MoveDirection.x * -48)
			marble:WaitForChild("BodyAngularVelocity").MaxTorque = Vector3.new(30000,30000,30000)
			if char.Humanoid.MoveDirection == Vector3.new(0,0,0) then
				marble:WaitForChild("BodyAngularVelocity").MaxTorque = Vector3.new(0,0,0)
			end
		elseif not marble then
			break
		end
	end
end)

--< Delete the players marble
DeleteMarble.Event:Connect(function(player, char, ball, weld, s) -- s = script
	if ball then
		char:FindFirstChildOfClass("Humanoid").PlatformStand = false

		weld:Destroy()
		ball:Destroy()

		char.PrimaryPart.CFrame *= CFrame.new(0, 10, 0)

	else
		warn("Marble cannot be found after ["..DeleteMarble.."] was fired.")
	end
end)

Game Link: Script Quest - Roblox

1 Like

You don’t show where you call DeleteMarble. Make sure you aren’t sending in your main Ball into that function because you are destroying it in that function which would stop things from working if indeed that is the Ball in your first script.

Its in the code

The main ball is never destroyed, it is cloned.

From a quick skim over without a lot of context, it is a bit difficult but to start is mostly:

  • I suggest you make sure CanCollide is actually on when touched
  • Any F9/Console errors?
1 Like

No errors weirdly, not sure if this is a roblox bug, so Im really confused on how I should trouble shoot this…

@quakage, @Druiren

My absolute dumbass forgot that when the player’s character loads in, the humanoid may not be active, therefore the cooldown will always be true.

Here’s the solution for anyone curious.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.