Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Touched script not firing or CanCollide not working?

Asked by 7 years ago

I thought this was a good script but for some reason they dont let you go through

h1 = game.Workspace.Kingdom.Hidden1
h2 = game.Workspace.Kingdom.Hidden2

script.Parent.Touched:connect(function()
    h1.CanCollide = false
    h2.CanCollide = false
end)
0
Are the parts single parts or models? Also i'm not sure if this is some sort of button, but this will fire when the part that the script is inside of it touched. It's also recommended to change those variables to local variables. SpazzMan502 133 — 7y

2 answers

Log in to vote
1
Answered by
Async_io 908 Moderation Voter
7 years ago

It would be best to provide more information as to your intention when asking a question. Assuming that you want the event to fire when a player touches the block, then you would have to make sure that it has a humanoid, as the Touched event fires whenever anything touches it. Also these have to be parts. If you're wanting to turn all the parts inside to a CanCollide then use a for loop.

local h1 = game.Workspace:WaitForChild('Kingdom'):WaitForChild('Hidden1') --I would recommend adding WaitForChild to these as it will wait for the Hidden1to load
local h2 = game.Workspace:WaitForChild('Kingdom'):WaitForChild('Hidden2')

script.Parent.Touched:connect(function(hit) 
    if hit.Parent:FindFirstChild('Humanoid')
        h1.CanCollide = false
        h2.CanCollide = false
    end
end)
0
I know why it is not working it is in a local script... is there anyway to fire it inside of a local script arrowman888 69 — 7y
0
it should work in a local script Async_io 908 — 7y
0
It finally worked thanks! arrowman888 69 — 7y
Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Add a regular script into a Kingdom then put this

Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
        script.Parent.CanCollide = false --false or true can work--
    end
end)

Or if you want it to open for few second do

Part.Touched:connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid")
    if H then
        script.Parent.CanCollide = false
        wait(5)
        script.Parent.CanCollide = true
    end
end)

Answer this question