Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Part effects work when part is sat on/not sat on, but when other part sat on effects glitch [EASY]?

For some reason, when I sit on a part and then get off of it the script works fine, but when I sit on another part, both the part that I had previously sat on and the part that I am now sitting on light up; https://gyazo.com/904a430766537e96d97ca06de386597d (photo of the hierarchy)

CODE:

script.Parent.Seat.Touched:connect(function(hit)
    while wait() do
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player.Character.Humanoid.Sit == true then
            for i,v in pairs (script.Parent.Model:GetChildren()) do
                if v:IsA("BasePart") then
                    v.Material = "Neon"
                end
            end
        end
            if player.Character.Humanoid.Sit == false then
                for i,v in pairs (script.Parent.Model:GetChildren()) do
                    v.Material = "SmoothPlastic"
                end
        end
    end
end)

Thanks!

2 comments

0

Can you please post a screen shot of what this is doing so I can understand myself

0

When a player sits on one of these parts, it turns neon: https://gyazo.com/b01f950a6b7b581e9bac9318c164f02d. When they get off, it turns smoothplastic.

1 answer

✓ Accepted answer

I see your problem you are not ending the 'while' loop, so it is going to check if the player is sitting or not forever, you need to find a place to add a 'break' in there so that the while loop stops

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.