Script doesn't work

I probably missed something.
Anyway the script is supposed to let only a player pass a transparent wall.

local part = script.Parent

local function CanCollide(otherPart)
	local partParent = otherPart.parent
	local humanoid = partParent:FindFirstChild("Humanoid")
	if humanoid then
		part.CanCollide = false
		wait(3)
		part.CanCollide = true
	end
end

is your function is connected to anything, or called anywhere? Try using Collision groups for the effect you are trying to achieve.

1 Like

it has too many errors according to me…
local partParent = otherPart.parent el parent esta mal escrito hagalo asi: local partParent = otherPart.Parent
In addition, we cannot answer clearly since we do not know how the function is triggered or if the part has the CanTouch activated, we practically do not know anything about the script

1 Like

Can you please give us some more details about the function of the script?

  • Is the script Server or Local ?
  • Is the script inside a part? [it mentions script.Parent So I believe it is.]
  • How do you call the function?
  • Are you getting any errors?

Usually to make something happen to 1 player only [locally] we use Local Scripts .

1 Like

Your script is not completed, so i added some things

local part = script.Parent

local function CanCollide(otherPart)
	local partParent = otherPart.parent
	local humanoid = partParent:FindFirstChild("Humanoid")
	if humanoid then
		part.CanCollide = false
		wait(3)
		part.CanCollide = true
	end
end
1 Like

Where did you even call the function?

1 Like

It is a script, but i changed the RunContext to Client.
Yes, the script is inside the part.
Crap, I forgor to put the line part.Touched:Connect(CanCollide())
Yes, there are errors in Output, it says attempted to index nil with Parent

1 Like

took all of your tips and came up with this, still had the index nil error:

local part = script.Parent

local function CanCollide(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChild("Humanoid")
	if humanoid then
		part.CanCollide = false
		wait(3)
		part.CanCollide = true
	end
end

part.Touched:Connect(CanCollide())
1 Like

The issue is that instead of connecting the function, you are calling the function then connecting nil. It should be

local part = script.Parent

local function onHit(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildOfClass("Humanoid")
	if humanoid then
		part.CanCollide = false
		task.wait(3)
		part.CanCollide = true
	end
end

part.Touched:Connect(onHit)
2 Likes

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