Greetings! I made a script that mimics Mouse.Target on mobile with the use of TouchTapInWorld, however, I am experiencing an issue.
TouchTapInWorld = UserInputService.TouchTapInWorld:Connect(function(Position, TappedByUI)
print("Tapped")
if not TappedByUI then
print("Its not UI.")
local WorldRay = Camera:ScreenPointToRay(Position.X, Position.Y)
local RayParams = RaycastParams.new()
local Raycast = Workspace:Raycast(WorldRay.Origin, WorldRay.Direction, RayParams)
print("Raycast successful")
if Raycast then -- Stops after this
print("We got a result")
if Raycast.Instance then
print("We got an instance")
if Raycast.Instance.Parent:IsA("Model") or Raycast.Instance:IsA("Part") then
print("Valid 1")
if Raycast.Instance:IsDescendantOf(Workspace._Plots[Player.Team.Name].ItemHolder) then
print("Valid 2")
if Raycast.Instance.Parent:IsA("Model") then
ReplicatedStorage.DeleteItem:FireServer(Raycast.Instance.Parent)
elseif Raycast.Instance:IsA("Part") then
ReplicatedStorage.DeleteItem:FireServer(Raycast.Instance)
end
end
end
end
end
end
end)
The last print statement I got was “Raycast successful”
So this means that there isn’t a RaycastResult
Please look over my code and tell me what to change.
I am also fairly new to raycasts as this is my first code that uses Raycasts.
Thanks in advance!
Sincerely, Willi