How do i make this work?

I tried using it, and it gave me this error:
image

local tweenservice = game:GetService("TweenService")

local function baseplateturn(degrees)
	tweenservice:Create(workspace.Baseplate,TweenInfo.new(5,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(0,degrees,0)}):Play()
end

local chaosfunctions = {
	["Base180"] = baseplateturn(180),
	["Base90"] = baseplateturn(90)
}

while true do
	wait(15)
	local functionrandom = math.random(1,2)
	local yeah = chaosfunctions[functionrandom]
	yeah()
end

Try this

local tweenservice = game:GetService("TweenService")
local function baseplateturn(degrees)
    tweenservice:Create(workspace.Baseplate,TweenInfo.new(5,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(0,degrees,0)}):Play()
end

local chaosfunctions = {
    ["Base180"] = baseplateturn(180),
    ["Base90"] = baseplateturn(90)
}

local Names = {}
for Name in pairs(chaosfunctions) do
    table.insert(Names,Name)
end

while true do
    wait(15)
    local functionrandom = Names[math.random(1,2)]
    local yeah = chaosfunctions[functionrandom]
    yeah()
end

It just gave me this: image

You could consider this.

local tweenservice = game:GetService("TweenService")

local function baseplateTurn(degrees)
	tweenservice:Create(workspace.Baseplate,
		TweenInfo.new(5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0, false, 0),
		{["CFrame"] = workspace.Baseplate.CFrame * CFrame.Angles(0, math.rad(degrees), 0)}
	):Play()
end

local chaosData = {
	["Base180"] = 180,
	["Base90"] = 90
}

local function getRandom()
	local tab = {}
	for i,v in pairs(chaosData) do
		table.insert(tab, {Name = i, Value = v})
	end
	return tab[math.random(1, #tab)]
end

while true do
	local random = getRandom()
	if random then
		baseplateTurn(random.Value)
	end
	wait(15)
end

But i’m not just gonna use the Baseplate turn, i’m going to add other events.

Ah, lemme edit then. One second.

Try this.

local tweenservice = game:GetService("TweenService")

local function baseplateTurn(degrees)
	tweenservice:Create(workspace.Baseplate,
		TweenInfo.new(5, Enum.EasingStyle.Cubic, Enum.EasingDirection.InOut, 0, false, 0),
		{["CFrame"] = workspace.Baseplate.CFrame * CFrame.Angles(0, math.rad(degrees), 0)}
	):Play()
end

local chaosData = {
	["Base180"] = {
		Function = baseplateTurn,
		Data = 180
	},
	["Base90"] = {
		Function = baseplateTurn,
		Data = 90
	}
}

local function getRandom()
	local tab = {}
	for i,v in pairs(chaosData) do
		table.insert(tab, {Name = i, Data = v})
	end
	return tab[math.random(1, #tab)]
end

while true do
	local random = getRandom()
	if random then
		random.Data.Function(random.Data.Data)
	end
	wait(15)
end

Would this work?

local tweenservice = game:GetService("TweenService")
local function baseplateturn(degrees)
	tweenservice:Create(workspace.Baseplate,TweenInfo.new(5,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(0,degrees,0)}):Play()
end

local chaosfunctions = {
	["baseplateturn90"] = {["Function"] = baseplateturn, ["Values"] = {90}},
	["baseplateturn180"] = {["Function"] = baseplateturn, ["Values"] = {180}}
}

while true do
	wait(15)
	local randomthing = math.random(1,2)
	local functionrandom = chaosfunctions[randomthing]
	functionrandom.Function(functionrandom.Values)
end

The error means that you are attempting to call something that does not exist make sure that the names in the explorer are the same as the script.

What do you mean by that? I am trying to call a function, not a object in the explorer.

local tweenservice = game:GetService("TweenService")

local function baseplateturn(degrees)
	tweenservice:Create(workspace.Baseplate,TweenInfo.new(5,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(0,degrees,0)}):Play()
end

while true do
	wait(15)
	local functionrandom = math.random(1,2)
	if functionrandom = 1 then
        baseplateturn(90)
    else
        baseplateturn(180)
    end
end

Try this. If it doesn’t work, tell me and send the output message.

If I’m correct, the error was that you were firing the functions already in the table before the script had a change to run, after the function ran it removed itself from the table which made it look like you were accessing a nil object. These other ideas people are giving you should help you with your problem, I’m just explaining what happened.

And also, we are here to answer your question, and not tutor you. So please don’t ask people to change their scripts to what you want.

The error means something in the script does not exist. For example, I have a model called “Test” and I call it “test” in the script. It will not recognize that you are trying to call the same thing. I would need to change the name to “Test” instead of “test”.

I don’t think you understand the gist of this post, it’s not something in workspace it’s a function. He is only accessing Baseplate which never gets deleted in the script. A function in a table is appearing nil so that’s another reason why that error could occur.

1 Like

Yes, but when I program things and I get that error it usually means I messed up in workspace, and/or in the function. I believe it may be both. Which is what I was trying to say. (Sorry if I was not clear, I hope this helps)

1 Like

Try this maybe:
local tweenservice = game:GetService(“TweenService”)

local function baseplateturn(degrees)
tweenservice:Create(workspace.Baseplate,TweenInfo.new(5,Enum.EasingStyle.Cubic,Enum.EasingDirection.InOut,0,false,0),{Orientation = Vector3.new(0,degrees,0)}):Play()
end

local chaosfunctions = {
[“Base180”] = baseplateturn(180),
[“Base90”] = baseplateturn(90)
}

while true do
wait(15)
local functionrandom = math.random(0,#chaosfunctions)
local yeah = chaosfunctions[functionrandom]
yeah()
end