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") thenisn’t running when the player stops touching the part. How do I fix this?
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 RemoteEventsplease lmk. I’d like to do this without using RemoteEvents
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)
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
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!