What do you want to achieve? Keep it simple and clear!
I am trying to make a button that will make the map night and make lamps start to Disco. ( Change Color )
What is the issue? Include screenshots / videos if possible!
It keeps returning as an Error: The current identity (2) cannot settings() (lacking permission 1) ( Attempting to change the timeout length since I got an error about timeout. )
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I haven’t been able to figure out why it’s erroring.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local CD = script.Parent.ClickDetector
local t = game.Lighting.ClockTime
local part = script.Parent
local ws = game.StarterGui.Warning.Frame
local time1 = 0
local complete = 30
settings().Studio.ScriptTimeoutLength = -1
for _, v in pairs (game.Workspace:GetDescendants()) do
if v.Name["Meshes/lamba_Cube.004"] then
wait(5)
function onMouseClick()
while true do
part.Name = BrickColor.new(math.random(0.1,1), math.random(0.1,1), math.random(0.1,1))
wait(.1)
time1 = time1 + .1
if time1 == complete then
break
end
end
end
CD.MouseClick:Connect(onMouseClick)
end
end
function onMouseClick()
ws.Visible = true
wait(5)
while true do
t = 0
wait(.1)
t = 1
wait(.1)
time1 = time1 + .1
if time1 == complete then
break
end
end
end
CD.MouseClick:Connect(onMouseClick)
It puts the script in time out because it does not have enough time to process. In every while true do loop you want to add a wait() in it to provide time to process.
First of all, I would clear up some of the variables at the beginning because you don’t need them.
Secondly, you edit a GUI in StarterGui… That will not replicate to any clients already in the game. You need to access the player’s PlayerGui, preferably by using a RemoteEvent.
Third, do not loop through the workspace’s descendants like that Instead make a table of all of your “Meshes/lamba_Cube.004” and loop through that.
You defined 2 global functions with the exact same name… and then changed the function connected to CD.MouseClick
part.Name = BrickColor.new()
Really?
Side notes:
Use RunService instead of a while loop
Avoid using wait(), especially since we have task.wait()
Use less local variables, especially for things you only call once or twice, particularly the constant you defined as “complete”
Get into the habit of using game:GetService() instead of game.ServiceName
Your code could look more similar to this:
local lighting = game:GetService("Lighting")
local rstorage = game:GetService("ReplicatedStorage")
local runservice = game:GetService("RunService")
local CD = script.Parent.ClickDetector
local MeshTable = {} --[[This would be the table with
all of your color-changing lights]]
local function changeColors()
for i, v in pairs(MeshTable) do
v.Color = Color3.new(math.random(0,1),math.random(0,1),math.random(0,1))
--// ^^ Customize to your heart's content ^^
--// Note that the color changing will be visible to the whole server
--// To make local, create a RemoteEvent to change the color as well
end
end
do --// I used a do block to keep the local variables where I need them
local connection
local waitTime = 3 --// The time between each color change
CD.MouseClick:Connect(function(player)
if connection then
connection:Disconnect()
else
rstorage.DecoyRemoteEvent:FireClient(player)
--// You would want to change any GUI's in the RemoteEvent using PlayerGui
local t = 0
connection = runservice.Heartbeat:Connect(function(dt)
--// dt is the change in time since the last frame
t += dt
if t >= waitTime then
t -= waitTime
changeColors()
end
end)
end
end)
end
(I wrote this on the Dev Forum, please be patient with any syntax errors or spelling mistakes!)
Honestly the code you have is extremely cursed. Either this is an elaborate troll or you fell for a terribly made tutorial, but I hope some of this was useful for you!