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

Player is not a valid member of Workspace?

Asked by 4 years ago

So basically I'm trying to teleport myself to someone when they click a TextButton which will be the Help button. I made this Local Script below to activate a Server Script to teleport me to the person who presses the button:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = game.ReplicatedStorage.Teleport

local button = script.Parent
local player = game.Players.LocalPlayer
local toggle = false

button.MouseButton1Click:connect(function()
local Players = game:GetService("Players")
    if Players.Kaisarys then
        print("Kaisarys was found.")
        Teleport:FireServer(player)
    end
end)

After they press the button if I am in-game it will fire the RemoteEvent that will activate the following Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage.Teleport

local function TeleportAdmin(player)
    local Players = game:GetService("Players")
    if Players.Kaisarys then
    game.Workspace.Kaisarys.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.player.HumanoidRootPart.CFrame)
    end
    end

Teleport.OnServerEvent:Connect(TeleportAdmin)

The problem is that it seems to work until the teleport is about to be done, the Output says that the player is not a valid member of Workspace, but considering that I got the player using the Local Script and transferred it to the Server Script, shouldn't the Server Script find the player?

I just wanted to make it so the teleport work, but if you have some spare time and is willing to help me with that I wanted to know how to use a table to store admin names so I could include the name of other people to the table so they would get teleported if I were offline.

1 answer

Log in to vote
0
Answered by
ImTrev 344 Moderation Voter
4 years ago
Edited 4 years ago

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage.Teleport

local function TeleportAdmin(player)
    local Players = game:GetService("Players")
    if Players.Kaisarys then
        game.Workspace.Kaisarys.HumanoidRootPart.CFrame =   CFrame.new(player.CharacterHumanoidRootPart.CFrame)
    end
end

Teleport.OnServerEvent:Connect(TeleportAdmin)

What your script did was try to find "player" in the workspace, which it isn't a thing. Now there are multiple ways I could've gone at the changed line but they would all do the same thing. I would also add a check to see if the player has a character. If you need anymore help just respond to this post.

EDIT: What I changed was CFrame.new(game.Workspace.player.HumanoidRootPart.CFrame) to CFrame.new(player.CharacterHumanoidRootPart.CFrame).

EDIT 2: game.Workspace.Kaisarys.HumanoidRootPart.CFrame = player.Character.CharacterHumanoidRootPart.CFrame

0
It says that HumanoidRootPart is not a valid part of Player if I don't add Character while if I add player.Character it says: ServerScriptService.Script:7: invalid argument #1 to 'new' (Vector3 expected, got CFrame) Kaisarys 19 — 4y
0
Sorry for that. Look at the new edit, I forgot .Character. ImTrev 344 — 4y
Ad

Answer this question