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:
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.
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.
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
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?
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)