Cancollide is being lazy rigt now

i cant believe im doing this

  1. What do you want to achieve? kitchen gun- i dont really know-

  2. What is the issue? cancollide is literally being stopped

  3. What solutions have you tried so far? The developer hub bad i’ve tried everything from checking and removing and stuff and i see nothing

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
this is my code :sad:

can = false
tween_service = game.TweenService
create = Instance.new
script.Parent.Head.Touched:Connect(function(hit)
	if can == false then
		can = true
		if can == true then
			local human = hit.Parent:FindFirstChild("Humanoid")
			if human then
				fake = game.ServerStorage.ServerGUIs.DamageIndicatorSlimeGUI:Clone()
				fake.Parent = script.Parent.Head
				human:TakeDamage(game.ServerStorage.ServerValues.SlimeDamage.Value)
				warn("DAMAGED!"..human.Health)
				print(hit.Parent.Name)
				local guiTween2 = tween_service:Create(fake.TextLabel,
					TweenInfo.new(1, 
						Enum.EasingStyle.Quad,
						Enum.EasingDirection.Out,
						0,
						false,
						0
					),
					{TextTransparency = 1;TextStrokeTransparency = 1}
				)
				
				local guiTween = tween_service:Create(fake,
					TweenInfo.new(1, 
						Enum.EasingStyle.Quad,
						Enum.EasingDirection.Out,
						0,
						false,
						0
					),
					{ExtentsOffsetWorldSpace = Vector3.new(0, 5, 0)}
				)
				-- Play statements --
				guiTween2:Play()
				guiTween:Play()
				
				guiTween.Completed:Connect(function(playbackState)
					fake:Remove()
				end)

				
				local root = human.Parent:FindFirstChild("HumanoidRootPart")
				local att = create("Attachment", root)
				
				local fire = script.Parent.Head.Fire:Clone()
				fire.Parent =  root
				
				local anim = human:FindFirstChildOfClass("Animator")
				
				local paralyze = anim:LoadAnimation(game.ServerStorage.ServerAnimations.Electro_Slime_Shock)
				paralyze:Play()
				human.WalkSpeed = 0
				human.JumpPower = 0
				
				task.wait(2)
				fire.Enabled = false
				paralyze:Stop()
				human.WalkSpeed = 16
				human.JumpPower = 50
				
				task.spawn(function()
					repeat task.wait()	
						human:TakeDamage(5)
					until fire.Enabled == false
				end)
			end
		end
	end
	
	task.wait(0.2)
	can = false
end)

What do you mean by this? It doesn’t look like your code handles CanCollide.


Regardless, I noticed that can = false at the end of the function is outside the if can == false block. Consequently, when can is set to true, can is set to false task.wait(0.2) seconds later before the damage-dealing code can fully complete, which might be the reason for “CanCollide being lazy”.

Moving can = false inside the if can == true block might solve the issue. Here’s some code to demonstrate it more clearly.

local part = script.Parent
local can = false

part.Touched:Connect(function(part)
	if not can then 
		can = true
		task.wait(1)
		print("Ok!")

        task.wait(0.2)      -- this will work
        can = false         -- can is set to false in a better place
	end
	
	-- task.wait(0.2)       -- probably won't produce the result you want!
	-- can = false          -- the code will run a lot even when can is true
end)
1 Like

this created a more bigger problem, winter slime and electro slime’s heads instantly disappear

It looks like you’re trying to create an effect where a player is damaged and paralyzed when touched by your script’s “Head” part. To do this, you’re using the Touched event of the Head part to detect when a player has been touched.

However, it looks like you’re encountering an issue where the Touched event is not firing properly. One possible reason for this is that the Touched event is being blocked by the CanCollide property of the Head part.

The CanCollide property determines whether or not a part can interact with other objects in the game world. If the CanCollide property is set to false, the part will not be able to collide with other objects and will not trigger the Touched event when touched.

To fix this issue, you can set the CanCollide property of the Head part to true. This will allow the part to collide with other objects and will enable the Touched event to fire properly.

Here is an example of how you could modify your code to set the CanCollide property of the Head part to true:

local head = script.Parent.Head

-- Set the CanCollide property of the Head part to true
head.CanCollide = true

head.Touched:Connect(function(hit)
...
end)

This code sets the CanCollide property of the Head part to true, which will allow the part to collide with other objects and will enable the Touched event to fire properly.

(you also did a mistake in your name title lol)

This actually isn’t true, this is managed by CanTouch.
Are you sure CanTouch is on? If it’s off the event won’t fire

1 Like

Thank you for correcting me, his CanTouch might be off.

image