Unable to cast value to Object on line 37
The Place1 function is supposed to send over the name and location arrays to a seperate LocalScript using the teleportPlayerEvent inside of ReplicatedStorage. I think the problem might be with the teleportPlayerEvent variables.
Script:
local Players = game:GetService("Players")
local teleportPlayerEvent = Instance.new("RemoteEvent")
teleportPlayerEvent.Parent = game.ReplicatedStorage
teleportPlayerEvent.Name = "teleportPlayerEvent"
local names = {
"Location 1", -- name of place 1
"Location 2", -- name of place 2
}
local locations = {
CFrame.new(-40, 143.3, 14.5), -- where place 1 is
CFrame.new(-75, 143.3, 14.5), -- where place 2 is
}
for i = 1, #names,1 do
local part = Instance.new("TextButton")
part.Name = "Button"..i
part.Text = names[i]
part.Position = UDim2.new(0, 0, 0, (i * 210)-210)
part.Size = UDim2.new(1, -100, 0, 200)
part.TextScaled = true
part.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
part.BorderSizePixel = 10
part.Font = "GothamBold"
part.Parent = script.Parent
end
local function Place1()
local placenumber = 1
teleportPlayerEvent:FireClient(names[placenumber],locations[placenumber]) -- line 37
-- game.Players.LocalPlayer.Character.Torso.CFrame = locations[2]
end
script.Parent.Button1.MouseButton1Down:connect(Place1)

2 comments
use :Connect(), :connect() may not work in the near future (this will prevent it being broken in a future update)
On line 37 if the server is teleporting the player my guess is it should be :FireServer