Attempt to call table value when teleporting player

Hello, could anyone help me debug this code?
Whenever I try to teleport back a stage in my obby game, the server side script says that I am “attempting to call a table value”. Both variables in line 6 and 7 print correctly, so I am unsure what is broken.

Thank you for looking at these scripts!

ServerScript for teleporting player:

local teleleportplayer = game.ReplicatedStorage.TeleportPlayer
local checkpoints = game.Workspace.Checkpoints

teleleportplayer.OnServerEvent:Connect(function(player, stagetoteleport)
	print(tostring(stagetoteleport))
	print(tostring(checkpoints:FindFirstChild(stagetoteleport).CFrame))
	print(tostring(player.Character.HumanoidRootPart.CFrame))
	
	player.Character.HumanoidRootPart.CFrame = checkpoints:FindFirstChild(stagetoteleport).CFrame + Vector3(0, 2, 0)
end)

LocalScript for handling button presses:

local player = game.Players.LocalPlayer
local gui = game.Players.LocalPlayer.PlayerGui.ScreenGui
local leftbutton = gui.LeftButton
local rightbutton = gui.RightButton
local stagelabel = gui.StageLabel
local stage = player.leaderstats.Stage
checkpoints = game.Workspace.Checkpoints
teleportplayer = game.ReplicatedStorage.TeleportPlayer

leftbutton.MouseButton1Click:Connect(function(player)
	if stage.Value > 0 then
		stagetoteleport = stage.Value - 1
		teleportplayer:FireServer(stagetoteleport)
	end
end)

Prints and errors:

At the end of the function in the server script, there’s a small typo in Vector3(0, 2, 0) (it’s supposed to use the Vector3.new() constructor).

Updating that to Vector3.new(0, 2, 0) should fix the error

Tysm! This worked perfectly :smiley:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.