Hello, I made a teleporter and I have a problem when I go through the tp the raycast goes back even though the attachment is still at the handle.
Video: robloxapp-20230601-1808347.wmv (1.1 MB)
Teleport Script
local Modules = game:GetService("ReplicatedStorage"):WaitForChild("Client_Modules")
local Zone = require(Modules.Zone)
local container = script.Parent
local zone = Zone.new(container)
local debounce = {}
local cooldown = 1
local range = 9
function getSurface(trigger, rootPart, hit)
local params = RaycastParams.new()
params.FilterDescendantsInstances = {trigger}
params.FilterType = Enum.RaycastFilterType.Include
local surface = nil
local distance = (trigger.Position - rootPart.Position).Magnitude
local direction = (trigger.Position - rootPart.Position).Unit * math.ceil(distance + 3)
local startPos = rootPart.Position
local result = workspace:Raycast(startPos, direction, params)
if result then
local normal = result.Normal
surface = normal
end
return surface
end
function Touched(hit)
if hit.Parent:FindFirstChild("Humanoid") and not debounce[hit.Parent] then
debounce[hit.Parent] = true
local character = hit.Parent
local rootPart = character:WaitForChild("HumanoidRootPart")
local surface = getSurface(container, rootPart, hit)
if surface then
rootPart.Position = rootPart.Position + script.Parent.CFrame.LookVector * surface.Z * range
end
task.wait(cooldown)
debounce[character] = nil
end
end
container.Touched:Connect(Touched)
just create the raycast module yourself personally I wouldnt recomment using that module. Here is a sample of what I do to accomplish simillar result and can be done client or server.
for _, attachment in ipairs(attachments) do
if attachment:IsA('Attachment') then
local lastPosition = attachment.WorldPosition
local startTime = tick()
spawn(function()
while tick() - startTime <= duration do
local currentPosition = attachment.WorldPosition
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {tool, char}
local direction = (currentPosition - lastPosition).Unit * 1 -- extend the raycast as far as possible
local raycastResult = workspace:Raycast(lastPosition, direction, raycastParams)
-- If the raycast didn't hit anything, we'll use the end of the raycast as the position
local hitPosition = raycastResult and raycastResult.Position or (lastPosition + direction)
local trailPart = Instance.new("Part")
trailPart.Anchored = true
trailPart.CanCollide = false
trailPart.Size = Vector3.new(.1, .1, (hitPosition - lastPosition).Magnitude)
trailPart.CFrame = CFrame.lookAt(lastPosition, hitPosition) * CFrame.new(0, 0, -trailPart.Size.Z / 2)
trailPart.Parent = workspace
trailPart.Color = Color3.fromRGB(255, 0, 4)
if raycastResult then
if raycastResult.Instance then
if raycastResult.Instance.Parent then
if raycastResult.Instance.Parent:FindFirstChild('Humanoid') then
if osTouched < os.time() - .5 then
osTouched = os.time()
raycastResult.Instance.Parent.Humanoid:TakeDamage(33)
end
end
end
end
end
Debris:AddItem(trailPart, 0.5)
lastPosition = currentPosition
RunService.Heartbeat:Wait()
end
end)
end
end
I tried your script and it worked, but it feels less responsive/less accurate? But, I want to try investigate the module to see if I can actually find the problem. Thanks for the help if I can’t find a solution I’ll give you the solution. Thanks again!
The script i send you has to be in a runservice.Stepped:Wait() loop maybe thats the issue it cant be in wait() maybe that is it compare it to the one in my game it feels responsive there so im not sure u probably using wait()
not sure is it the same on the game i sent ?? and dont know make sure u run the attachment for i ,v loop in stepped loop or heartbeat loop then i guess and u could change inside from heartbeat to stepped possibly