While I was testing my code, I encountered a problem when testing it on a local server. The code below is placed in a local script inside the PlayerGUI
local plr = game.Players.LocalPlayer local char = plr.Character char.Torso.Touched:connect(function(hit) print("Rome") end
When the function is activated on a local server, It will not print Rome but instead return "Torso is not a valid member of Model". I find this problem extremely odd. All help is appreciated.
It is most likely because you are assuming the character is already loaded, try this solution.
local plr = game.Players.LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() char:FindFirstChild('Torso').Touched:Connect(function(hit) print("Rome") end
CharacterAdded
.local plr = game:GetService("Players").LocalPlayer local char = plr.Character or plr.CharacterAdded:Wait() char.Torso.Touched:Connect(function(hit) -- :connect is deprecated, switch to :Connect print("Rome") end