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

How do I change part properties when 5 parts are a specific color?

I'm trying to make the exit door's transparency 1, and the can collide off. I've tried doing the script below, but nothing! I have no idea how to make this work, I would love it if someone knew how to help!

if script.Parent.LeverOneLight.Transparency == 0 then
	if script.Parent.LeverTwoLight.Transparency == 0 then
		if script.Parent.LeverThreeLight.Transparency == 0 then
			if script.Parent.LeverFourLight.Transparency == 0 then
				if script.Parent.LeverFiveLight.Transparency == 0 then
					game.Workspace.Map1.ExitDoor.Transparency = 1
					game.Workspace.Map1.ExitDoor.CanCollide = false
					game.StarterGui.ExitOpened.TextLabel.Visible = true
					wait(3)
					game.StarterGui.ExitOpened.TextLabel.Visible = false
				end
			end
		end
	end
end

2 comments

1

Search the difference between StarterGui and PlayerGui.

0

no u (burnedddddddddddddddddd)

2 answers

✓ Accepted answer

Ok, first off I don't get why you have so many if statements.

if example == 0 and example1 == 0 and example2 == 0 then

You can use if followed by and

In English, this means if all the conditions I state in this line are met, then execute this.

You could also use or if you are trying to give it options.

if example == 0 or example1 == 0 or example2 == 0 then

in English, this means if ANY of the stated conditions are met, then execute what I write below.

An If statement will not constantly keep checking if the parameters are met. They will check once and that is it...that is unless you inclose them in something that will make them check again.

you can use a loop, or a function.

Now I'm going to make an assumption. This is a script inside of a model. That means we can't use .Changed events.

This basically means the best thing I can see to use is a while or repeat loop.

Secondly, you are asking game.StarterGui to make something visible. StartedGui exists only to feed newly joined players a User Interface.

The best thing you can do is use a RemoteEvent and store it in ReplicatedStorage

and have two scripts, a local script and a server script.

--- this should be the original server script
--- this should be the original server script
local event = game:GetService("ReplicatedStorage").RemoteEvent -- you can replace RemoteEvent with the name of your RemoteEvent inside of replicated storage. 
while true do
	wait(0.01)
if script.Parent.LeverOneLight.Transparency == 0 and script.Parent.LeverTwoLight.Transparency == 0 and script.Parent.LeverThreeLight.Transparency == 0 and script.Parent.LeverFourLight.Transparency == 0 and script.Parent.LeverFiveLight.Transparency == 0 then
                    game.Workspace.Map1.ExitDoor.Transparency = 1
                    game.Workspace.Map1.ExitDoor.CanCollide = false
                    event:FireAllClients()
break
        end 
                end

this next stuff should be in a DIFFERENT script

-- local script put inside of starter player scripts
local event = game:GetService("ReplicatedStorage").RemoteEvent
local player = game.Players.LocalPlayer
event.OnClientEvent:connect(function()
	player.PlayerGui.ExitOpened.TextLabel.Visible = true
	wait(3)
	player.PlayerGui.ExitOpened.TextLabel.Visible = false
end)

Hope this helps. If you don't understand this feel free to leave a comment or try to tag me in the community chat.

Assuming the lever lights aren't Visible when the game starts, you have to use a loop to keep on checking until they are. The second error is that you are using StarterGui instead of PlayerGui. StarterGui is the "sample" interface that will be replicated into the player once one joins. The PlayerGui is the replicated StarterGui.

Here's what your script should look like:

players = game:GetService("Players"):GetPlayers()

repeat wait() until
if script.Parent.LeverOneLight.Transparency == 0 then
    if script.Parent.LeverTwoLight.Transparency == 0 then
        if script.Parent.LeverThreeLight.Transparency == 0 then
            if script.Parent.LeverFourLight.Transparency == 0 then
                if script.Parent.LeverFiveLight.Transparency == 0 then --The script will be stuck in this loop until the conditions are met.
	                end
	            end
	        end
	    end
	end
end
                    game.Workspace.Map1.ExitDoor.Transparency = 1 --Once the script breaks free from the loop, these commands will be run.
                    game.Workspace.Map1.ExitDoor.CanCollide = false
		    for i, player in pairs(players) do --Looping through each player in the game.
                    player.PlayerGui.ExitOpened.TextLabel.Visible = true
                    wait(3)
                    player.PlayerGui.ExitOpened.TextLabel.Visible = false

Hope this helps

2 comments

0

In the output, I just got the error, "Workspace.Map1.LeverLights.LightOn.Script:4: Expected identifier when parsing expression, got 'if'

1

just wanna say I like your code. Mine had mistakes in it too. But me and epicboy got it worked out. Good answer, except for the repeat loop trips an error

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