Players.Infuriashon.PlayerGui.LocalScript:79: attempt to call a table value

I’m trying to pick random part to teleport the player to when pressing the button. But this bug happens:

Players.Infuriashon.PlayerGui.LocalScript:79: attempt to call a table value

so um help please if you need rest of the script tell me

thanks :smiley:

It should be teleparts[part].CFrame

Also! Remove the {} on line 77, they’re not needed.

The parentheses imply a function, brackets are for indexing values in a table.

As an extra tip, I’d use the random object.

At the top of your script, make

local random = Random.new()

Then make line 78

local part = random:NextInteger(1, #teleparts)
1 Like

I also mispelled CFrame which is an oof

1 Like

Please show you were you define “HRP”;
Im going to make a guess that teleparts is a table so;
the teleport line would be:

-- if you haven't defined "part"
HRP.CFrame = teleparts["part"].CFrame 
-- this is when you defined "part" as a string:
HRP.CFrame = teleparts[part].CFrame

it’s at the top of the script it’s humanoid root part. I’ll send here.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local HRP = char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local PlayerGui = plr:FindFirstChild("PlayerGui")
local blackscreen = PlayerGui.BlackScreen.BlackFrame
local tweenservice = game:GetService("TweenService")
local circleplayeractivity = game.ReplicatedStorage.Values.CirclePlayerActivity

game.ReplicatedStorage.RemEvents.PlayerPos.OnClientEvent:Connect(function()
	char.Archivable = true
	if char.Archivable == true then
		local clonedchar = char:Clone()
		clonedchar.Parent = cam
		local root = clonedchar.HumanoidRootPart
		cam.CameraSubject = root
		local humanoid = clonedchar.Humanoid
		local animation = clonedchar.Animate.idle.Animation1
		local idle = humanoid:LoadAnimation(animation)
		idle:Play()
		idle.Looped = true
		root.CFrame = workspace.TeleportPart.CFrame + Vector3.new(0, 5, 0)
		game.Lighting.ClockTime = 24
		game.Lighting.ColorCorrection.TintColor = Color3.fromRGB(233, 255, 255)
		game.Lighting.FogStart = 70
		game.Lighting.FogEnd = 200
		game.Lighting.Brightness = 0
		game.Lighting.FogColor = Color3.fromRGB(80, 80, 80)
		game.Lighting.OutdoorAmbient = Color3.fromRGB(0, 0, 0)
		game.Lighting.Ambient = Color3.fromRGB(67, 67, 67)
		workspace.Snowstorm.ParticleEmitter.Enabled = true
		workspace.SkyMesh.Mesh.Scale = Vector3.new(-30000,-30000,-30000)
	end
end)

game.ReplicatedStorage.RemEvents.CameraPos.OnClientEvent:Connect(function(tf)
	repeat 
		cam.CameraType = Enum.CameraType.Scriptable
	until
	cam.CameraType == Enum.CameraType.Scriptable
	cam.FieldOfView = 50
end)

game.ReplicatedStorage.RemEvents.FadeUI.OnClientEvent:Connect(function()
	local tweeninf = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
	local screendark = tweenservice:Create(blackscreen, tweeninf, {Transparency = 0})
	screendark:Play()
	wait(3.5)
	local screenclear = tweenservice:Create(blackscreen, tweeninf, {Transparency = 1})
	screenclear:Play()
end)

game:GetService("RunService").Stepped:Connect(function()
	if circleplayeractivity.Value == "Cabin" and not "Off" then
		cam.CFrame = workspace.CabinCamera.LogCamera.CFrame
	elseif circleplayeractivity.Value == "Character" and not "Off" then
		cam.CFrame = workspace.CameraTurner.StarterCamera.CFrame
	end
end)

PlayerGui.PlayButton.PlayButton.MouseEnter:Connect(function()
	local playbutton = PlayerGui.PlayButton.PlayButton
	local playframe = PlayerGui.PlayButton.PlayFrame
	playframe.ImageColor3 = Color3.fromRGB(27, 83, 0)
	playbutton.TextColor3 = Color3.fromRGB(148, 0, 0)
end)

PlayerGui.PlayButton.PlayButton.MouseLeave:Connect(function()
	local playbutton = PlayerGui.PlayButton.PlayButton
	local playframe = PlayerGui.PlayButton.PlayFrame
	playframe.ImageColor3 = Color3.fromRGB(0, 0, 0)
	playbutton.TextColor3 = Color3.fromRGB(255, 255, 255)
end)

PlayerGui.PlayButton.PlayButton.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Values.CirclePlayerActivity.Value = "Off"
	local teleparts = {game.Workspace.TeleportParts:GetChildren()}
	local part = math.random(1, #teleparts)
	HRP.CFrame = teleparts[part].CFrame + Vector3.new(0,5,0)
end)

HRP.Touched:Connect(function(touched)
	if touched.Name == "QueueWall1" then
		HRP.CFrame = touched.CFrame + Vector3.new(0,3,5)
	end
end)

I edited my response to include all required changes. It should work after that.

2 Likes

Do you wish the player to teleport to a random part or a specific part?

If random do like CheekySquid did
or use math.random()

HRP.CFrame = teleparts[math.random(1,#teleparts)].CFrame
1 Like

can you explain how this works so i can get better at scripting?

Let me explain,

  1. First you state that teleparts is an array of children under workspace.TeleportParts
    An arry is as follows:
myTable = {"hi","my","name","is","KJ","!!"}

so the “value” is the string and LUA gives every value an “index”, else it’d be harder to find it.

print(myTable[1]) --> "hi"
print(myTable[2]) --> "my"
print(mytable[6] --> "!!"

Then we want randomly choose between 1 or every child and all the children are in the table so;
If we use:

print(myTable) --> 6

as it gives the amount of values inside the table.

then we randomize between 1 and the amount which is in the table

math.random(1,#myTable)

After which we have a random index which is part of the table, so we put it all together;

myTable[math.random(1,#myTable)] 
1 Like

Thanks a lot! I’m pretty decent at scripting, but I’ve never really consistently used random.new or math.random until now as I didn’t need it yet. I bookmarked it so I can return if I have this same question.

:smiley:

edit: thanks to @CheekySquid as well

No problem, credit to @CheekySquid as well! :smiley:

1 Like