Issue with workspace:GetPartsInPart(Part)

local Part = script.Parent

while true do wait()
    local Check = workspace:GetPartsInPart(Part)
    local Active = false
    local Name

    for i, v in ipairs(Check) do
        if v.Parent:FindFirstChild("HumanoidRootPart") then
            Active = true
            Name = v.Parent.Name
            if Active then
                game.Players[Name].Multi.TempValue.Value = 2
            else
                game.Players[Name].Multi.TempValue.Value = 0
            end
        end
    end
end

game.Players[Name].Multi.TempValue.Value = 0 will never work because if v.Parent:FindFirstChild("HumanoidRootPart") then isn’t running when the player stops touching the part.
How do I fix this?

1 Like

I can’t put it outside of the for loop because Name wouldn’t exist.

I’ve decided to use RemoteEvent. I didn’t want to at first because I thought it would make a mess. But if theres a way I can do this without using RemoteEvents please lmk. I’d like to do this without using RemoteEvents

wait i don’t understand, could you be more clear about what0s the problem and what you want to achieve?

game.Players[Name].Multi.TempValue.Value = 0 never runs

I’ve tried something similar to this before. In the output it said that “Name” Doesn’t exist

Do you want the value of TempValue to be set to 0 when the player exits the perimeter? You should be able to use the Part.Touched and Part.TouchEnded events like this:

local Part = script.Parent

Part.Touched:Connect(function(Touched)
	if Touched.Name == "HumanoidRootPart" then
		game.Players:GetPlayerFromCharacter(Touched.Parent).Multi.TempValue.Value = 2
	end
end)

Part.TouchEnded:Connect(function(Touched)
	if Touched.Name == "HumanoidRootPart" then
		game.Players:GetPlayerFromCharacter(Touched.Parent).Multi.TempValue.Value = 0
	end
end)
1 Like

Part.Touched is glitchty inconsistent. The Value will be set to 0 randomly even if the player is touching the Part. That’s why I used workspace:GetPartsInPart(Part)

To clarify, is the part in question a non collide perimeter, or is it a floor? Because if it is a floor, it is likely your past code using the Touched event has registered the player leaving because their foot stepped off of the part.

If it sets 0 even if the player is touching the part then you must be doing something wrong. the code that @XSiggeManx wrote is right so you should try it

The part is a non collide perimeter,

You should try the code I wrote. I have tested my code and I don’t experience any problems with Touched and TouchEnded.

I’ve tried the code already. The Value will be set to 0 randomly even if the player is touching the Part.

I’m not sure why it is happening on your side, because for me it works fine. If you want to go back to your original method of using workspace:GetPartsInPart, you could define a table which keeps track of all players inside of the perimeter. When a part from a new character enters, you add the player to the list and change their “TempValue”. When the last of their part leaves, you remove them from the list and change their value back to 0.

Oh wow that’s weird. I could’ve sworn .Touched had some errors. I’m having some minor bugs like the value isn’t changing, but I tried this in a different way and it works. Thanks!

alright, if your problem is solved click the solved check.

I’ve already done that, wdymmmmmmmmmmmmmm?

oh my bad didn’t see that. Have a good day!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.