I’m having issues with some client sided code accurately running .Touched. When I move the character through the block (rootpart is the HumanoidRootPart of the character), I’m not getting a touch. For some reason though, on occassion, it’ll touch. But once it does touch a block, it’s like it’s disabled from touching again for a long period of time (or never again at all).
The following is being run inside of a local script, inside a GUI, inside the PlayerGui.
function onTouched(part)
print(part.Name) -- This fails to print (thus fails to touch?) 90% of the time
if part.Name == "Finish" then
if sector == 1.5 then
TouchSector()
sector = 2
TouchSector()
addLapEvent:FireServer()
else
bt = elapsedTime()
cc = false
cclap = false
wr = false
wrlap = false
script.Parent.LiveTimer.LapStart.Value = true
script.Parent.LiveTimer.LapStartTime.Value = elapsedTime()
end
sector = 0
elseif part.Name == "Check1" and sector == 0 then
TouchSector()
sector = .5
elseif part.Name == "Check2" and sector == .5 then
TouchSector()
sector = 1
displayLapTime(script.Parent.LiveTimer.Label.Text,5)
elseif part.Name == "Check3" and sector == 1 then
TouchSector()
sector = 1.5
end
end
function test(model)
for _, piece in pairs(model:GetChildren()) do
if piece:IsA("Part") then
print(piece.Name) -- This prints out the name of the blocks, fine.
end
end
end
test(workspace.Track.Checkpoints) -- These are the blocks that aren't reacting to the onTouched function.
rootPart.Touched:connect(onTouched)
Notable factors:
Workspace.Track is a cloned in map from ServerStorage
A touched event oriented script run on the server is firing accurately on the problematic bricks. (Just me running a test)
CanTouch is true (should be obvious due to the case above)
The GUI is just in playergui and brought in through that.
The touched event is firing some some parts, just not the parts I actually want it to be firing on.
The only thing that I noticed would be the checkpoints. If you cloned them from the ServerStorage then the client wont fire the touch event because it never knew it was cloned. Hope that makes sense.
I thought this too, so I setup some blocks in workspace to eliminate this being an issue (doesn’t make sense for it to be an issue in honesty though…)
I believe the issue may be related to the following:
My player model is inside of a car, the car’s NetworkOwnership is set to the server.
My guess is that this somehow bypasses being considered “a result of physics movement” which is what is needed for Touched to fire.
But I don’t exactly see why this would be the case. If the car is being moved along by the player’s input, regardless of the car’s NetworkOwnership, why does it matter. Or is the fact the server owns the car, make it now such that the movement of the car is considered the server CFraming it?
I’m honestly lost as to what the reasoning behind this issue could be.
Update: I removed the NetworkOwnership script, and yes, it would appear that this is for some reason the case. If anyone has any idea why this is the case, I’d love to know.
It’s the HumanoidRootPart touching Checkpoint blocks.
When this script is enabled, the touched does not fire.
local seat = script.Parent
local Players = game:GetService("Players")
local car = script.Parent.Parent
car:MakeJoints()
seat.Changed:Connect(function(prop)
while seat.Anchored == true do
wait()
end
if prop == "Occupant" then
local humanoid = seat.Occupant
if humanoid then
local player = game:GetService("Players"):GetPlayerFromCharacter(humanoid.Parent)
seat:SetNetworkOwner(player)
car.Name = humanoid.Parent.Name.."Car"
script.Parent.CarStatus.DriverName.Value = humanoid.Parent.Name
wait(1)
end
seat:SetNetworkOwner(nil)
end
end)
When this script ^ is disabled, the touched does fire.
This is just your simple tank chassis car that this is being done with.
4 tires (balls) with surface hinge (as in surface hinges, not constraints) and a vehicle seat.
It would appear this update is why I cannot do this. Seems strange, but when setting the car’s ownership to the server, it sets the character inside the car to the server as well, which means that I can’t run touched from the client on the character’s model because the client no longer owns the character.