I’m using stage lights I am editing to move the way I want but I can only move them one direction and stop when I want them to move one direction, then another, then another, etc.
The issue is I can only get the first movement to happen and the second never does.
I have tried to end the first solution so that the second would start after but nothing happens even when I tried that.
Basically, I keybind the movement and want to add more movement to my stage lights.
function script.MoveTest.OnServerInvoke()
for i,v in pairs (game.Workspace.MLights:GetChildren())
do
if v.Name == "CPSS"
then
v.LightingController.Tilt:Invoke(90)
v.LightingController.Pan:Invoke(90)
elseif v.Name == "CPSSa"
then
v.LightingController.Tilt:Invoke(-90)
v.LightingController.Pan:Invoke(-90)
end
if v.Name == "CPSS"
then
v.LightingController.Tilt:Invoke(0)
v.LightingController.Pan:Invoke(0)
elseif v.Name == "CPSSa"
then
v.LightingController.Tilt:Invoke(0)
v.LightingController.Pan:Invoke(0)
end
end
end```
There is a possibility of an error being there in the script that receives then invoke. Can you show me the scripts inside the parts that actually tilt stuff?
local tiltMotor, panMotor
local speed = 2
local b = script.Parent:WaitForChild("Body"):WaitForChild("Head"):WaitForChild("Beam")
local d = script.Parent:WaitForChild("Body"):WaitForChild("Head"):WaitForChild("Lens")
local l = b:WaitForChild("SpotLight")
script:WaitForChild("Dimmer").OnInvoke = function(val)
if val == 0 then
b.light.Enabled = false
d.Transparency = 1
l.Enabled = false
else
l.Enabled = true
d.Transparency = 0
b.light.Enabled = true
end
l.Brightness = 2 / 255 * val
print(val)
end
function setupMotors()
local base = script.Parent:WaitForChild("Body"):WaitForChild("Pan"):WaitForChild("PanBase")
local part = script.Parent:WaitForChild("Base"):WaitForChild("Base")
panMotor = Instance.new("Motor", script)
panMotor.Name = "PanMotor"
panMotor.Part0 = base
panMotor.Part1 = part
panMotor.C0 = CFrame.new(2.2,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(90), math.rad(90), 0) -- anchor point 1 relative offset
panMotor.C1 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(90),0, 0) -- anchor point 2 relative offset
base.Parent.Weld.Disabled = false
base = script.Parent:WaitForChild("Body"):WaitForChild("Head"):WaitForChild("HeadBase")
part = script.Parent:WaitForChild("Body"):WaitForChild("Pan"):WaitForChild("TiltBase")
tiltMotor = Instance.new("Motor", script)
tiltMotor.Name = "TiltMotor"
tiltMotor.Part0 = base
tiltMotor.Part1 = part
tiltMotor.C0 = CFrame.new(0,-0.01,0) * CFrame.fromEulerAnglesXYZ(math.rad(-180), math.rad(0), math.rad(90))
tiltMotor.C1 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(0), 0) -- CFrame.new(-1.4,0,0) :: distance from tiltbase to headbase
base.Parent.Weld.Disabled = false
panMotor.MaxVelocity = math.rad(10)
tiltMotor.MaxVelocity = math.rad(10)
panMotor.DesiredAngle = math.rad(0)
tiltMotor.DesiredAngle = math.rad(0)
end setupMotors()
function SetColor(color)
b.light.Color = ColorSequence.new(Color3.new(color.r, color.g, color.b))
l.Color = Color3.new(color.r, color.g, color.b)
b.Parent.Lens.Color = Color3.new(color.r, color.g, color.b)
end
function pan(angle)
panMotor.DesiredAngle = math.rad(angle)
panMotor.MaxVelocity = math.rad(math.abs(math.deg(panMotor.CurrentAngle) - math.deg(panMotor.DesiredAngle)))/(60 * speed)
end
function tilt(angle)
tiltMotor.DesiredAngle = math.rad(angle)
tiltMotor.MaxVelocity = math.rad(math.abs(math.deg(tiltMotor.CurrentAngle) - math.deg(tiltMotor.DesiredAngle)))/(60 * speed)
end
function setSpeed(spd)
speed = spd
end
function script.Pan.OnInvoke(angle)
pan(angle)
end
function script.Tilt.OnInvoke(angle)
tilt(angle)
end
function script.Speed.OnInvoke(value)
setSpeed(value)
end
function script.Color.OnInvoke(col)
SetColor(col)
end
pan(0)
tilt(0)
setSpeed(1)'''
How if statements work is they check if the statement is then then goes down the list. They cant detect for both of them at once. Simply declare a new if statement instead of encapsulating the scope
local x = 6
local y = 1
if x == 6 then
print("a")
elseif y == 1 then
print("b")
end
--will only print a
if x == 6 then
print("a")
end
if y == 1 then
print("b")
end
--prints a and b
I think i figured something out! So I think I should of shown the keybind script too!
Player = game.Players.LocalPlayer
a = script.Parent.Parent.Admins
Admins = {a.User1.Value,a.User2.Value,a.User3.Value,a.User4.Value,a.User5.Value}
for i,v in pairs (Admins) do
if Player.Name == v then
mouse = Player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "k" then
game.Workspace.KDHandler1.MoveTest:InvokeServer()
end
end)
end
end```
I added a second invokeserver at the end so (before the “end” lol) and it changed the movement, but now the stage light sort of tries to move both ways at once so it just sort of moves a bit and then back to its original position. This is how this looks now:
Player = game.Players.LocalPlayer
a = script.Parent.Parent.Admins
Admins = {a.User1.Value,a.User2.Value,a.User3.Value,a.User4.Value,a.User5.Value}
for i,v in pairs (Admins) do
if Player.Name == v then
mouse = Player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "k" then
game.Workspace.KDHandler1.MoveTest:InvokeServer()
game.Workspace.KDHandler1.MoveTest2:InvokeServer()
end
end)
end
end
and so now the second moment is accounted for by the “MoveTest2” Also sorry if i don’t make much sense english is my second language and I’m new to LUA but I am trying my best!
Just wanted to let you know I found the solution! All I had to do was edit the script for my keybind and add wait(x) in between the two functions so that it when i ran the script it would have time to complete the first function before the next one started! Now it looks like this:
Player = game.Players.LocalPlayer
a = script.Parent.Parent.Admins
Admins = {a.User1.Value,a.User2.Value,a.User3.Value,a.User4.Value,a.User5.Value}
for i,v in pairs (Admins) do
if Player.Name == v then
mouse = Player:GetMouse()
mouse.KeyDown:connect(function(key)
if key == "k" then
game.Workspace.KDHandler1.MoveTest:InvokeServer() --first function
wait(1)
game.Workspace.KDHandler1.MoveTest2:InvokeServer() ---second function
end
end)
end
end