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

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

Asked by 4 years ago
Edited by DeceptiveCaster 4 years ago

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)
0
I don't think you understand how FireServer() works, but this looks alright. Have you tried using print()'s? DeceptiveCaster 3761 — 4y
0
Yeah, I tried to put "print (Works)" under the PlayerHere:MoveTo part but it didn't print it. DennisSense 23 — 4y
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. Sebgamingkid 147 — 4y
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. DeceptiveCaster 3761 — 4y
View all comments (4 more)
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. DeceptiveCaster 3761 — 4y
0
Could you possibly fix the script for me then? DennisSense 23 — 4y
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 DennisSense 23 — 4y
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(). DeceptiveCaster 3761 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
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!

Ad

Answer this question