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

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

Asked by
Vid_eo 126
6 years ago

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!

0
Can you please post a screen shot of what this is doing so I can understand myself SynthetickDev 188 — 6y
0
When a player sits on one of these parts, it turns neon: https://gyazo.com/b01f950a6b7b581e9bac9318c164f02d. When they get off, it turns smoothplastic. Vid_eo 126 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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

0
Thanks! Vid_eo 126 — 6y
Ad

Answer this question