The “teleport to” button works, but the other one is the one I have problems with. Now it’s half fixed. It teleports me to other player and not the other player to me. But I really don’t know why
playerValue is the player from the frame in which the button is. Every player has its own frame.
LocalScript:
local localValue = game.Players.LocalPlayer
local function Bring()
script.Parent.RemoteEvent:FireServer(localValue)
end
script.Parent.Bring.MouseButton1Click:Connect(Bring)
You do not need to fire the player from the local script, as the player is always going to be defined if it’s firing to the server because it runs on the client, so you can remove local value in your local script.
Ok in your LocalScript, why are you passing the Player as 1 of your arguments? The OnServerEvent has 1 parameter, which is the Player Object & you can easily reference the Player’s Character by simply doing Player.Character without having the need to even do that in the first place
Again, just reference the Player as OnServerEvent:Connect(function(Plr), there is no need to pass it twice as it’s already the default parameter
script.Parent.RemoteEvent.OnServerEvent:Connect(function(Plr)
local Char = Plr.Character
if Char and Char:FindFirstChild("HumanoidRootPart") then
Char:MoveTo(Char.HumanoidRootPart.Position)
end
end)
Also 1 more thing, what purpose are you doing just by moving the Character in the exact same spot???
Or like @Modxno said you can do this, I’m using his script just adding something that he forgot to.
local Part = game.Workspace.Part
script.Parent.Triggered:Connect(function(Player)
Player.Character.HumanoidRootPart.CFrame = CFrame.new(Part.Position)
end)
localValue is the player who presses the button
playerValue is the player from the frame with the button
I hope this clarifies it
My problem is just, that the player is not teleported to me when pressing “bring”. Instead, I am getting teleported to the player. I don’t know how I could fix that.
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent
local Button = script.Parent
local TeleportInstance = Button.playerValue.Value.Character --//Reference your player value
--//Functions
Button.MouseButton1Click:Connect(function()
RemoteEvent:FireServer(TeleportInstance)
end)
Server Script:
--//Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//Variables
local RemoteEvent = ReplicatedStorage.RemoteEvent
--//Functions
RemoteEvent.OnServerEvent:Connect(function(player, TeleportInstance)
TeleportInstance:PivotTo(player.Character.PrimaryPart.CFrame)
end)
--------/// Vars \\\--------
local event = game.ReplicatedStorage.Events.TP
local Button = script.Parent
--------/// Main \\\--------
Button.MouseButton1Click:Connect(function(plr)
event:FireServer(Button.Name) -- Have each tp button be named to each player's userId or just put the value of the plr your teleporting to
end)
ServerScript
--------/// Vars \\\--------
local event = game.ReplicatedStorage.Events.TP
local plrs = game:GetService("Players")
--------/// Main \\\--------
event.OnServerEvent:Connect(function(Plr,plrID)
local toPlr = plrs:GetPlayerByUserId(plrID)
Plr.Character:MoveTo(toPlr.Character.PrimaryPart.CFrame)
end)