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)
It's because you didn't define who to FireClient to, so you just need to add the player to send it to.
But, as you said that you're casting to your other LocalScript, :FireClient() can not run in this script. You should just just create a modulescript which is written to by this script, where the other script will require it and read from there.