Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to cast value to object?

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

0

use :Connect(), :connect() may not work in the near future (this will prevent it being broken in a future update)

0

On line 37 if the server is teleporting the player my guess is it should be :FireServer

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.