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

My invisible brick is not working?

Asked by
Relatch 550 Moderation Voter
9 years ago

I use this script to make it where it moves a bot to it's spawning location when it touches the part. No matter what I do, it still bypasses the brick, and it gets into the lobby and kills the players that aren't attacking it. I get no errors, I just get a bunch of print that says something like "Invisible Block: " and a bunch of numbers. I use 2 scripts that basically tie in together.

My script works amazing in studio, just how I want it to. Then, I go in-game, and the longer/bigger script doesn't do anything whatsoever. In studio, it still continues to work even after the bot is respawned. I don't know anything else to do, I tried everyone's suggestions.

Invisible block script:

local SpawnPos=Vector3.new(36.89, 3, -114)
local Bots=workspace.BotArea

script.Parent.Touched:connect(function(Hit)
    if Hit:IsDescendantOf(Bots) then
        for _,Bot in pairs(Bots:GetChildren()) do
            if Hit:IsDescendantOf(Bot) then
                Bot:MoveTo(SpawnPos)
            end
        end
    end
end)

Sends bot back into it's spawning position script:

local Bot=script.Parent

function FindNearestTorso(Pos)
    local BestTarget=nil
    local BestDist=500
    for i,v in pairs(game:GetService("Players"):GetPlayers()) do
        if v.Character and v.Character:FindFirstChild("Torso") then
            local Character=v.Character
            local Torso=Character.Torso
            local Dist=(Torso.Position-Pos).magnitude
            local Ray=Ray.new(Pos,(Torso.Position-Pos).unit*Dist)
            local Part,Pos=workspace:FindPartOnRayWithIgnoreList(Ray,{Bot,Character})
            if not Part and Dist<BestDist then
                BestTarget=Torso
                BestDist=Dist
            end
        end
    end
    return BestTarget
end

while true do
    wait()
    local target = FindNearestTorso(Bot.Torso.Position)
    local SpawnPos=Vector3.new(36.89, 3, -114)
    if target ~= nil then
        Bot.Humanoid:MoveTo(target.Position, target)
    else
        Bot.Humanoid:MoveTo(SpawnPos)
    end
end
0
It seems that "Invisible Block" is the closest block. Maybe the Touched function isn't firing when the bot touches it (touched isn't very reliable :/). Maybe you could check to see if the player it's going towards is inside a certain radius (the lobby)? Thewsomeguy 448 — 9y
0
There is no Connection Line. woodengop 1134 — 9y
0
instead of commenting, please add a answer with a script. Relatch 550 — 9y
0
Basically, when he first spawns the brick works. Then, I go in and kill him, and then go out. Then I go back in, and out to test the "else Bot.Humanoid:MoveTo(SpawnPos)" and he goes straight through the brick. Relatch 550 — 9y
View all comments (3 more)
0
People generally comment to get clarification and pose ideas of answers. We generally discourage people from posting answers that they are not sure about. Please let people continue to comment! Unclear 1776 — 9y
0
You should remove line 5 in your first script, there is not really a point of it. alphawolvess 1784 — 9y
0
Alright, I am looking at the top code block, I don't see anything wrong with it. My suggestion is making multiple prints and see where the script is failing... I am sorry I can not be any more help... M39a9am3R 3210 — 9y

3 answers

Log in to vote
1
Answered by
ImageLabel 1541 Moderation Voter
9 years ago

I optimized it but pretty much used your system, so I assume I don't have to go into much detail explaining it all. I also added a little bit to it to make it a little more fun :D


local bot, agility, bestTarget, target, bestWait do
    agility = 0.25
    bot = script.Parent;

    bestTarget = function (position)
        local Victim = nil
        local Distance = 100

        for key, player in pairs(game.Players:GetPlayers()) do
            if pcall(function() return player.Character.Torso end) then
                local character = player.Character
                local torso = character.Torso
                local magnitude = (torso.Position - position).magnitude

                local ray = Ray.new(position,(torso.Position - position).unit * magnitude)
                local hit, position = workspace:FindPartOnRayWithIgnoreList(ray,{bot, character})

                if not hit and magnitude <= Distance then
                    Victim = torso
                    Distance = magnitude
                end
            end
        end
        return Victim
    end

    bestWait = function()
        return (not target and agility or 0.5)
    end
end



while wait(bestWait()) do
    local iSpawn = Vector3.new(36.89, 3, -114)
    local target = bestTarget(bot.Torso.Position)

    if target ~= nil then
        bot.Humanoid:MoveTo(target.Position)
        target.Parent.Humanoid.Died:connect(function()
            target = nil
        end)
    else
        bot.Humanoid:MoveTo(iSpawn)
    end
end
Ad
Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

You code looks right. Although not a real solution, I can simplify the touch script.

local SpawnPos=Vector3.new(36.89, 3, -114)

script.Parent.Touched:connect(function(hit)
    if hit.Parent and hit.Parent.Name == "Bot" then
        hit.Parent:MoveTo(SpawnPos)
    end
end)

Might as well try it. As I said, your code looks good.

Log in to vote
-6
Answered by 9 years ago

Instead of using a great big script, you should... 1. Go into Roblox Studio 2. Click on the brick 3. If the Properties pane is not open already, please open it. 4. Find Transparency, set that to 1. Done!

If you want to make sure no one knows of it's existence, uncheck CanCollide.

Answer this question