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

Radius of a Player to a block?

Asked by 5 years ago
Edited by RubenKan 5 years ago

I have tried every radius like script to magnitude to finding the nearest torso. I'm trying to make a script which if a player gets inside of a certain radius to a block it will give them a GUI, Make them speak and give them an item but this script wont work. (BY THE WAY, this is a SCP script called SCP-3020 - Depression so don't mind the text)

function findNearestTorso(pos)
    local list = game.Workspace:children()
    local torso = nil
    local dist = 50
    local temp = nil
    local human = nil
    local temp2 = nil
    for x = 1, #list do
        temp2 = list[x]
        if (temp2.className == "Model") and (temp2 ~= script.Parent) then
            temp = temp2:findFirstChild("Torso")
            human = temp2:findFirstChild("Humanoid")
            if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then
                if (temp.Position - pos).magnitude < dist then
                    torso = temp
                    dist = (temp.Position - pos).magnitude
                end
            end
        end
    end
    return torso
end


while true do
    wait(0.1)
    local target = findNearestTorso(script.Parent.Top.Position)
    if target ~= nil then

        targ = target
        hum = targ.Parent:findFirstChild("Humanoid")
        if (hum == nil) then
            script.Parent.Head.Fail:play()
        end
        local char = hum.Parent
            local plr = game.Players:GetPlayerFromCharacter(char)
            local Lonely = plr.PlayerGui.Lonely

        wait(40)

        enabled = true
    end
end

Using this script I try to make it so it makes them speak.

0
This is not a asking question to get a new script I'm just wondering if there is a way to fix it or not. oshawat00 62 — 5y
0
What goes wrong with the script you posted? fredfishy 833 — 5y
0
It doesn't work... oshawat00 62 — 5y
0
https://www.youtube.com/watch?v=p9GVCfgHrzY You're bringing everyone down! theCJarmy7 1293 — 5y
0
Man sorry. oshawat00 62 — 5y

1 answer

Log in to vote
1
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Something like this example is a good way to check if a player is within a radius of something: https://scriptinghelpers.org/questions/60744/best-way-to-check-if-a-player-is-within-radius-of-something#59095. You can manipulate it to create the region around the part rather than the player themselves if you want.

I get that the whole depression thing is part of the SCP, but just a heads up roblox probably wont allow it & will moderate your game.

0
ALOT of sites use the SCP oshawat00 62 — 5y
0
Thanks I will try oshawat00 62 — 5y
0
This doesn't work. When I get near the block it does not print anything the Part is named correctly but nothing works oshawat00 62 — 5y
Ad

Answer this question