When I enable cantouch via script, touch doesn’t work at all. Yesterday all scripts worked, today none of the scripts related to cantouch work. I see that the object in the cantouch workspace changes its value to true, but when I touch, nothing happens
local TweenService = game:GetService("TweenService")
local hinge = script.Parent.Doorframe.Hinge
local prompt = script.Parent.Base
local op = prompt.Open.Value
local op2 = prompt.Open2.Value
local goalOpen = {}
goalOpen.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(20), 0)
local goalOpen2 = {}
goalOpen2.CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(100), 0)
local tweenInfo = TweenInfo.new(
1.5,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local tweenInfo2 = TweenInfo.new(
5.1,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
false,
0
)
local tweenOpen = TweenService:Create(hinge, tweenInfo2, goalOpen)
local tweenOpen2 = TweenService:Create(hinge, tweenInfo, goalOpen2)
function enter()
tweenOpen:Play()
script.Parent.Base.Creak:Play()
wait(5.1)
script.Parent.Enter2.CanTouch = true
end
function enter2()
tweenOpen2:Play()
script.Parent.Base.door_open:Play()
end
script.Parent.Enter.Touched:Connect(function(hit)
local Plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") and op == false then
op = true
enter()
end
end)
script.Parent.Enter2.Touched:Connect(function(hit)
local Plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if hit.Parent:FindFirstChild("Humanoid") and op2 == false then
op2 = true
enter2()
end
I solved the problem, it turns out that now when you touch an object and its properties change, you need to touch the object again, I had a large touch object on the floor, but now it doesn’t work
Update:
This is not a solution to the problem, if someone touches the object and the properties change, the script will not work again.
If the Touched:Connect signal runs when the CanTouch property is false, the signal won’t be connected at all, and it won’t work even if you later set the CanTouch property back to true.
If the Touched:Connect signal is connected to a part that has the CanTouch property set to true, and you then change the CanTouch property to false, the signal will automatically disconnect. You will need to reconnect it once the part’s CanTouch property is set back to true.
local TweenService = game:GetService("TweenService")
local hinge = script.Parent.Doorframe.Hinge
local prompt = script.Parent.Base
local op1 = prompt.Open.Value
local op2 = prompt.Open2.Value
local goalOpen1 = {CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(20), 0)}
local goalOpen2 = {CFrame = hinge.CFrame * CFrame.Angles(0, math.rad(100), 0)}
local tweenInfo1 = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tweenInfo2 = TweenInfo.new(5.1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tweenOpen1 = TweenService:Create(hinge, tweenInfo2, goalOpen1)
local tweenOpen2 = TweenService:Create(hinge, tweenInfo1, goalOpen2)
function enter()
tweenOpen1:Play()
script.Parent.Base.Creak:Play()
wait(5.1)
script.Parent.Enter2.CanTouch = true
end
function enter2()
tweenOpen2:Play()
script.Parent.Base.door_open:Play()
end
local function ConnectEnterSignal(EnterPart)
EnterPart.Touched:Connect(function(hit)
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid and EnterPart == script.Parent.Enter and op1 == false then
op1 = true
enter()
elseif Humanoid and EnterPart == script.Parent.Enter2 and op2 == false then
op2 = true
enter2()
end
end)
end
ConnectEnterSignal(script.Parent.Enter)
ConnectEnterSignal(script.Parent.Enter2)
script.Parent.Enter:GetPropertyChangedSignal("CanTouch"):Connect(function()
if script.Parent.Enter.CanTouch == true then
ConnectEnterSignal(script.Parent.Enter)
end
end)
script.Parent.Enter2:GetPropertyChangedSignal("CanTouch"):Connect(function()
if script.Parent.Enter2.CanTouch == true then
ConnectEnterSignal(script.Parent.Enter2)
end
end)
Can confirm that something strange is happenning. Numerous random things in our game just stopped working today (hopefully only in studio), all of them related to changing CanCollide or CanTouch during runtime.
A simple weird thing can easily be tested on a fresh place without scripts:
Press ‘Play’
Create a part, anchor it and make it bigger.
Disable CanCollide, CanQuery and CanTouch
Enable only CanCollide
The part starts behaving weirdly - it does not collide with the character or other parts, but you can stand on top of it, and it also prevents jumping from under it. This does not seem to happen when enabling either CanQuery or CanTouch first, and it also seems to fix itself after a while, but happens again if repeated.
Don’t know if it was like this with CanCollide before, but this is strange and very similar to what we started experiencing today - CanCollide and/or CanTouch randomly not working when turned on, even though everything worked reliably just a couple days before.