how can i connect the target function and player function into the server script so the server can bring the other player to me here is my local script
local player = game.Players.LocalPlayer player.Chatted:Connect(function(msg) local target --this would be the player that we're gonna tp to, its just a varibale to make things cleaner. if msg:lower():match("goto") then if game.Players:FindFirstChild(msg:sub(6)) then target = workspace:FindFirstChild(msg:sub(6)) print(target) player.Character.HumanoidRootPart.CFrame = CFrame.new(target.Head.Position) end end end) local player = game.Players.LocalPlayer player.Chatted:Connect(function(msg) local target --this would be the player that we're gonna tp to, its just a varibale to make things cleaner. if msg:lower():match("get") then if game.Players:FindFirstChild(msg:sub(6)) then target = workspace:FindFirstChild(msg:sub(6)) print(target) game:GetService("ReplicatedStorage"):WaitForChild("playertp").FireServer(player, target) end end end)
here is my server script
game.ReplicatedStorage:WaitForChild("playertp").OnServerEvent:Connect(function(player, target) target.HumanoidRootPart.CFrame = CFrame.new(player.Head.Position) end)
i get no errors from this in-game
There are a couple errors in each script that I can point out and fix for you.
Here's what your local script should look like:
local player = game.Players.LocalPlayer local remoteEvent = game.ReplicatedStorage:WaitForChild("playertp") player.Chatted:Connect(function(msg) if msg:lower():match("goto") then local targetPlayer = game.Players:FindFirstChild(msg:sub(6)) if targetPlayer and targetPlayer.Character then --Checks if the player and character is there player.Character.HumanoidRootPart.CFrame = CFrame.new(target.Head.Position) end elseif msg:lower():match("get") then local targetPlayer = game.Players:FindFirstChild(msg:sub(5)) --should be :sub(5) instead of :sub(6) if targetPlayer and targetPlayer.Character then remoteEvent:FireServer(targetPlayer.Character) --When firing, only fire the parameters, not the player end end end)
I made some edits so that the Chatted function isn't repeated twice. I also used a conditional statement to check whether or not the target is in the game, and whether his/her character is loaded.
Something to keep in mind is when you are firing a remote event to the server, you do NOT include player as a parameter. The server automatically receives it.
Here's what the server script should look like:
local remoteEvent = game.ReplicatedStorage:WaitForChild("playertp") remoteEvent.OnServerEvent:Connect(function(player, target) target.HumanoidRootPart.CFrame = CFrame.new(player.Character.Head.Position) --You forgot to address the Character of the player end)
Notice how the server automatically picks up who fired the remote event. It's the very first thing that it picks up in every :FireServer() case.
I hope this answers your question, let me know if you need any more details :)