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

I need help to teleport a player! I get no errors but it does not teleport them? [Solved]

I have it with a remove Event. I am trying to make it teleport a person which the username of the person is in the Server Script Storage Script as User.

This is in the LocalScript

local Name = game.Players
script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.Queue1:FireServer(Name.LocalPlayer)
end)

And this is in Server Script Storage

SpotI = game.Workspace.Queue1.SpotI
BringHere = game.Workspace.Queue1.SpotO
User = game.Workspace.Queue1.SpotOI.UserHere.Value

game.ReplicatedStorage.Queue1.OnServerEvent:Connect(function(PlayerHere)
    
User = PlayerHere.Name
SpotI.Touched:Connect(function(part)
    if part.Parent.Humanoid then
        if part.Parent.Humanoid.Health > 0 then
             PlayerHere:MoveTo(BringHere.Position)
        end
        end
end)
end)

8 comments

0

I don't think you understand how FireServer() works, but this looks alright. Have you tried using print()'s?

0

Yeah, I tried to put "print (Works)" under the PlayerHere:MoveTo part but it didn't print it.

0

You are doing it slightly incorrectly, but close. usually FireServer() will naturally pass the player instance that it is coming from. That may or may or may not be the issue but it really could be part of it.

0

Ok, so instead of doing 'part.Parent.Humanoid', you're better off using Players:GetPlayerFromCharacter() on part.Parent. This will check if a player has touched SpotI. You can then use the player that it found to check for a Humanoid, and then teleport that player. Furthermore, you can check to see if the player is PlayerHere.

0

And yes, Sebgamingkid is correct. Although LocalPlayer can't be replicated to the server, if you passed a valid argument to the server, that argument would be assigned to the second parameter given to the receiving function. The first parameter you give the function is actually assigned to the client that fired the event, which is a Player object.

0

Could you possibly fix the script for me then?

0

I removed the SpotI.Touched Part and only kept "game.Players[User]:MoveTo(BringHere.Position)" and now its saying MoveTo is not a valid member of players

0

Yeah, it doesn't work like that. Assign the player retrieved using GetPlayerFromCharacter() to a variable, then move that player's Character using MoveTo().

1 answer

SpotI = game.Workspace.Queue1.SpotI
BringHere = game.Workspace.Queue1.SpotO
User = game.Workspace.Queue1.SpotOI.UserHere.Value

game.ReplicatedStorage.Queue1.OnServerEvent:Connect(function(PlayerHere)
    
User = PlayerHere.Name
game.Players[User].Character:MoveTo(BringHere.Position)
print ("Works")

end) 

The problem was the ServerScriptStorage Script. This one works!

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