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

Who can add found this object in this spaces?

Asked by
Xufly 8
5 years ago
Edited 5 years ago

So, I have script. That script tping ball to me legs in button. With ball commans people can spawn ball in this positions (workspace, homepk, homegk, homecl, homecr, awaypk, awaygk,awaycl, awaycr. Script is -

local plr = game.Players.LocalPlayer
game:GetService("UserInputService").InputBegan:Connect(function(key,gpe)
    if not gpe then 
        if key.KeyCode == Enum.KeyCode.R then 
            local temp1 = 15
            local temp2 = nil
            for i,v in pairs(workspace:GetChildren()) do 
                if v:IsA("BasePart") and v.Name == "TPS" then 
                    local dist = (v.Position - plr.Character.Head.Position).magnitude
                    if dist < temp1 then 
                        temp2 = v
                        temp1 = dist
                    end
                end
            end
            if temp2 ~= nil then
                game.ReplicatedStorage.Events.NetworkOwnership:FireServer(temp2)
                temp2.CFrame = plr.Character:FindFirstChild("Right Leg").CFrame * CFrame.new(0,0,-3)
            end
        end
    end
end)

TPS is ball name, I want you helped me with adding this spaces upper like in this script

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
function Detach(name, parent)
    game:GetService("ReplicatedStorage").Events.RemoveWeld:FireServer(name, parent)
    for i,v in pairs(parent:GetChildren()) do 
        if v:IsA("Weld") and v.Name == name then 
            v:Destroy()
        end
    end
end
function Attach(name, part0, part1, ball, c0, c1)
    game:GetService("ReplicatedStorage").Events.Attach:FireServer(name, part0, part1, ball, c0, c1)
    local W = Instance.new("Weld")
    W.Name = "Keep"
    W.Part0 = part0
    W.Part1 = part1
    W.Parent = part0
    W.C0 = c0
    W.C1 = c1
end
local bll = nil
game:GetService("UserInputService").InputBegan:Connect(function(key,gpe)
    if not gpe then 
        if key.KeyCode == Enum.KeyCode.R and bll == nil then 
            local temp1 = 40
            local temp2 = nil
            for i,v in pairs(workspace:GetChildren()) do 
                if v:IsA("BasePart") and v.Name == "TPS" then 
                    local dist = (v.Position - plr.Character.Head.Position).magnitude
                    if dist < temp1 then 
                        temp2 = v
                        temp1 = dist
                    end
                elseif v.Name == "homegk" or v.Name == "homepk" or v.Name == "homecl" or v.Name == "homecr" or v.Name == "awaypk" or v.Name == "awaycl" or v.Name == "awaycr" then 
                    for _,x in pairs(v:GetChildren()) do 
                        if x:IsA("BasePart") and x.Name == "TPS" then            
                            local dist = (x.Position - plr.Character.Head.Position).magnitude
                            if dist < temp1 then 
                                temp2 = x
                                temp1 = dist
                            end
                        end
                    end
                end
            end
            if temp2 ~= nil then
                Detach("Keep", game.Players.LocalPlayer.Character:FindFirstChild("Right Arm"))
                wait()
                Attach("Keep", plr.Character:FindFirstChild("Right Arm"), temp2, nil, CFrame.new(0, 0, 0), CFrame.new(0.3, 0.3, 0.8))
                bll = temp2
            end
        end
    end
end)

mouse.Button1Down:Connect(function()
    if bll ~= nil then 
        Detach("Keep", game.Players.LocalPlayer.Character:FindFirstChild("Right Arm"))
        bll = nil
    end
end)

Answer this question