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

How to check if parent is a certain player?

Asked by 2 years ago
Edited 2 years ago

Hey, I wanna check if my tool's parent is a player. I used a table to get all the descendants of workspace and anchored them. But, when I hold out my tool, it is also anchored. I want something that can check if the tool's parent is a player and then skip the item.

local Event = game.ReplicatedStorage.Event.TimeStopEvent
local InUse = game.ReplicatedStorage.Event.InUse
local Sound = game.Workspace.TheWorldSound
local Resume = game.Workspace.ResumeTime
local Table = {}

game.ReplicatedStorage.Event.TimeStopEvent.OnServerEvent:Connect(function(player)
    local descendants = Workspace:GetDescendants() -- gets all things under workspace
    if game.ReplicatedStorage.Event.InUse.Value == false then
        game.ReplicatedStorage.Event.InUse.Value = true
        Sound:Play()
        game.Lighting.Gay.Saturation = -1
        game.Lighting.Gay.Enabled = true
        for i = 255, 0, -31.875 do
            game.Lighting.Gay.TintColor = Color3.fromRGB(i, 0, 255)
            wait()
        end
        for i = 0, 255, 31.875 do
            game.Lighting.Gay.TintColor = Color3.fromRGB(0, i, 255)
            wait()
        end
        for i = 255, 0, -31.875 do
            game.Lighting.Gay.TintColor = Color3.fromRGB(0, 255, i)
            wait()
        end
        for i = 0, 255, 31.875 do
            game.Lighting.Gay.TintColor = Color3.fromRGB(i, 255, 0)
            wait()
        end
        for i = 0, 255, 31.875 do
            game.Lighting.Gay.TintColor = Color3.fromRGB(255, 255, i)
            wait()
        end
        for i = 1, #descendants do -- Getting all the things under workspace and putting them in TABLE
            if descendants[i]:IsA("Part") or descendants[i]:IsA("MeshPart") then --checking each individual descendant
                if descendants[i].Anchored == false and descendants[i].Parent.Name ~= player.Name and descendants[i].Name ~= ("Handle") and descendants[i].Name ~= ("Baseplate") and not descendants[i].Parent:IsA ("Accessory") then
                    descendants[i].Anchored = true -- if all requirements met, they are anchored
                    table.insert(Table, descendants[i]) -- creates table of anchored descendants
                end
            end
        end
    elseif game.ReplicatedStorage.Event.InUse.Value == true then
        InUse.Value = false
        Resume:Play()
        for i = -1, 0, 0.125 do
            game.Lighting.Gay.Saturation = i -- ts effect
            wait()
        end
        for i = 1, #Table do -- take the table we made of the descendants from earlier and then unanchor them
            local descendants = Table[i] 
            descendants.Anchored = false
        end
        table.clear (Table)
    end
end)

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

You can just simply skip any instance that is a tool/is a child of a tool inside of your anchoring script. Something like

If not object:IsA(“tool”) or object.Parent == “tool” then
        — anchor script here
end

I dont have the script so I dont know exactly what your doing

0
for other players, their tool is also unfrozen 11cphun 0 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
local timeStopUser = player.Name -- You can also fire some events to set the variable's name to the player who used Time Stop

if (descendants[i].Parent.Name == timeStopUser) then
    -- Do something
end
0
basically i made a time stop script and it freezes everything during stopped time. what im trying to do is make everything stop apart from me and whatever im holding. also other players can use the tools as well so i need it to be a specific parent. 11cphun 0 — 2y
0
Alright, made changes to my answer, I believe that's what you wanted guest_20I8 266 — 2y
0
sorry i shouldve been more specific. everyone has the time stop so it cant be a specific player. it has to be the player that used the time stop that the sword isnt anchored. im gonna post the code so you know wwhats happening. 11cphun 0 — 2y
0
Alright bro, i've read ur codes, is there any problem with the codes?? Like error or something? guest_20I8 266 — 2y
View all comments (9 more)
0
no it works perfectly 11cphun 0 — 2y
0
apart from the Ws on workspace are uppercase 11cphun 0 — 2y
0
Hmm ok, what are the lines of codes that produce different result(s) than expected one(s)? guest_20I8 266 — 2y
0
none. everything (apart from my other script) works fine and as expected. 11cphun 0 — 2y
0
Alright, I've updated the codes again, hope that is what you wanted guest_20I8 266 — 2y
0
ok ill try it once my studio responds again 11cphun 0 — 2y
0
this unfortunately didnt work as whenever i used the parent name it would unanchor the parent instead of the sword 11cphun 0 — 2y
0
actually im positive it would work. i just need to make "timestopper" variable the person who stopped time. do you have any ideas? 11cphun 0 — 2y
0
actually no it doesnt work i just tested it with timestopper being a string of my name 11cphun 0 — 2y

Answer this question