Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Teleport Pads (Warp Pad) system having slight problems with player distance. How to fix?

Asked by 1 year ago
Edited 1 year ago

I’m trying to create a warp pad system and it works correctly. I’m trying to get the warp pad that the player is standing on but instead it get’s ALL the warp pads instead of the warp pad where the player is standing. Can anyone tell me why? If you need more information just ask!

The problem is the line that says “Player:DistanceFromCharacter” is getting every warp pad which is what the problem is but I can’t seem to figure how I can make it get the warp pad that the player is standing on

Recording:

https://www.xbox.com/play/media/DYAS7X5JD5

(Wait a little it may need to load)

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local WarpGui = PlayerGui.WarpGui
local TweenService = game:GetService("TweenService")
local WarpPads = game.Workspace.WarpPads
local Buttons = WarpGui.Frame
local GameFolder = game.ReplicatedStorage.GameFolder
local Events = GameFolder.Events
local WarpActive = WarpPads.WarpsActive






for i,WarpButtons in pairs(Buttons:GetChildren()) do
    for i,Warps in pairs(WarpPads:GetChildren()) do
        for i,Warps2 in pairs(WarpPads:GetChildren()) do
        if WarpButtons:IsA("TextButton") and Warps:IsA("UnionOperation") and Warps2:IsA("UnionOperation") and Player:DistanceFromCharacter(Warps2.Position)<1 then
            WarpButtons.MouseButton1Down:Connect(function()
                if WarpButtons.Name == Warps.Name and WarpButtons.Name then
                    WarpGui.Enabled = false
                        Events.Warp:FireServer(Warps,Warps2)
                        print(Warps2,Warps)
                    end
                end)
            end
        end
    end
end


function Open(P)
    if P == Player.Character.LeftFoot then
        WarpGui.Enabled = true
    end
end

function Close(P)
    if P == Player.Character.LeftFoot then
        WarpGui.Enabled = false
    end
end


for i, Pads in pairs(WarpPads:GetChildren()) do
    if  Pads.Name == "GuiPart" then
        Pads.Touched:Connect(Open)
    end
end


for i, Pads in pairs(WarpPads:GetChildren()) do
    if Pads.Name == "GuiPart" then
        Pads.TouchEnded:Connect(Close)
    end
end

script.Parent.Close.MouseButton1Down:Connect(function()
    PlayerGui.WarpGui.Enabled = false
end)

Answer this question