Touched script wont work?

Im making a invisible wall that when touched it plays a sound and lights come on there are 3 parts the local script is in serverscriptservice and heres the code:

       local part1 = workspace.WallForLogoLightEventThing.Part1
		local part2 = workspace.WallForLogoLightEventThing.Part2
		local part3 = workspace.WallForLogoLightEventThing.Part3
		local light = workspace.LogoSpotLights.SpotLight
		local light1 = workspace.LogoSpotLights.SpotLight1
		local lightsTurningOn = workspace.WallForLogoLightEventThing.LightsTurningOn

		part1.Touched:Connect(function()
			wait(1)
			light.LightBeam.Beam.Enabled = true
			light.LightPart.PointLight.Enabled = true
			light.LightBeam.SpotLight.Enabled = true
			lightsTurningOn:Play()
			wait(1.5)
			light1.LightBeam.Beam.Enabled = true
			light1.LightPart.PointLight.Enabled = true
			light1.LightBeam.SpotLight.Enabled = true
			lightsTurningOn:Play()

		end)
		part2.Touched:Connect(function()
			wait(1)
			light.LightBeam.Beam.Enabled = true
			light.LightPart.PointLight.Enabled = true
			light.LightBeam.SpotLight.Enabled = true
			lightsTurningOn:Play()
			wait(1.5)
			light1.LightBeam.Beam.Enabled = true
			light1.LightPart.PointLight.Enabled = true
			light1.LightBeam.SpotLight.Enabled = true
			lightsTurningOn:Play()

		end)
		part3.Touched:Connect(function()
			wait(1)
			light.LightBeam.Beam.Enabled = true
			light.LightPart.PointLight.Enabled = true
			light.LightBeam.SpotLight.Enabled = true
			lightsTurningOn:Play()
			wait(1.5)
			light1.LightBeam.Beam.Enabled = true
			light1.LightPart.PointLight.Enabled = true
			light1.LightBeam.SpotLight.Enabled = true
			lightsTurningOn:Play()

		end)

Local scripts don’t work in serverscript service. Place it in starter gui or starterpack

1 Like

Why would i place it in starterGui if im not making a gui though?

You don’t have to be making a gui to use scripts inside starter gui > local scripts just run from there so its an easy place to put them. Its not better to use one over the other, its just a place to run the script is how I see it.

1 Like

Like @Ryuunske said local scripts don’t run in serverscript service (its in the name (server)).

May I also suggest instead of creating a function for each touched of the different parts make one function and just fire that one function when a part is touched. it will make ur code look better and neat.

1 Like

Hello!

The local scripts in ServerScriptsService don’t work.

To make this code work, I suggest you put it in the StarterGui or in the StarterPlayer that is the parts in the game where the local scripts work. My advice is definitely to move it to the “physical part of the player” then to the StarterCharacterScripts

1 Like

I put it in StarterGui now it gives me this error 17:34:16.602 Script ‘Players.spydercam500.PlayerGui.LogoLightThing’, Line 1 - Studio - LogoLightThing:1
I believe i need to put a :WaitForChild(“The parts name here”) for it to work correct?

Feel free to put the local script in one of your parts.

Local scripts don’t run from the workspace I suggest you not do this.

1 Like

LocalScript (roblox.com)

As shown in this link, local scripts can only be run from

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service
    Its impossible to run a local script from the workspace. Check your information before you just throw it out.

Depends. Would there be an issue that the script is runing other things before something is loaded?

If so yes just add a waitforchild. even is u are unsure it should be fine

Yea I don’t think they can run in workspace. Not sure why ur code would have worked. U sure it was not a server script?

When these parts are touched, do you want these properties to change for the entire server or just the player who touched it?

1 Like

Oh, my bad yeah I thought he was using a script.

1 Like

Just the people who touched it hence why its a local script

I fixed it! It works now Thanks you for the help eveyone!

Okay, make sure to add a WaitForChild for the parts since they might not exist yet, and make sure the names are correct. Also, it appears that the parts all do the same exact thing when touched. You can simplify it by simply connecting them all to the same function call then. I believe that this code should work fine:

local logoLightThing = workspace:WaitForChild("WallForLogoLightEventThing")
local spotLights = workspace:WaitForChild("LogoSpotLights")
local part1 = logoLightThing:WaitForChild("Part1")
		local part2 = logoLightThing:WaitForChild("Part2")
		local part3 = logoLightThing:WaitForChild("Part3")
		local light = spotLights:WaitForChild("SpotLight")
		local light1 = spotLights:WaitForChild("SpotLight1")
		local lightsTurningOn = logoLightThing:WaitForChild("LightsTurningOn")

local function onTouch()
        wait(1)
		light.LightBeam.Beam.Enabled = true
		light.LightPart.PointLight.Enabled = true
		light.LightBeam.SpotLight.Enabled = true
		lightsTurningOn:Play()
		wait(1.5)
		light1.LightBeam.Beam.Enabled = true
		light1.LightPart.PointLight.Enabled = true
		light1.LightBeam.SpotLight.Enabled = true
		lightsTurningOn:Play()
end

part1.Touched:Connect(onTouch)
part2.Touched:Connect(onTouch)
part3.Touched:Connect(onTouch)

Oh, sorry, I did not see that post before I posted my response up above. Sorry about that, glad you fixed it!

1 Like