Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Unable to cast value to object?

Asked by 5 years ago
Edited 5 years ago

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)
0
use :Connect(), :connect() may not work in the near future (this will prevent it being broken in a future update) WideSteal321 773 — 5y
0
On line 37 if the server is teleporting the player my guess is it should be :FireServer Wafflecow321 457 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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.

Ad

Answer this question