I’m having an issue running a block of code to teleport to another place within a experience.
My issue code is right here Prints are just to see what’s running and what’s not
```game.Workspace.SpawnLocation.Touched:Connect((function(rot)
print("Found Part")
print("Part Touched")
if rot.Name ~= "HumanoidRootPart" then return end
print("Running")
local player = game.Players:GetPlayerFromCharacter(rot.Parent.Parent)```
Everything is printing and it is detecting my player model but the if rot.Name ~="HumanoidRootPart" then return end
Line is not running. I’m too confused as to way it isn’t running and I have tried solutions like rnaming the part its getting “rot” & other things but nothing seems to work. I was wondering if someone could help me out. I also haven’t found any other ideas on how to fix it on here.
I left part of the teleport script left out as it was running fine.
What do you mean by line is not running? Doesn’t it print “Running” at all? I tested your script(albeit edited it to not print “Found Part” and “Part Touched” all the time) and it printed “Running”. However, I see another problem in your script, being this line:
local player = game.Players:GetPlayerFromCharacter(rot.Parent.Parent)
Isn’t rot.Parent.Parent workspace? Maybe delete one of those .Parents.
Is this what you’re trying to do? This is a script inside a part. (probably doesnt need to be this nested but thought i get the point across)
local Players = game:GetService("Players")
local Part = script.Parent
Part.Touched:Connect(function(rot)
-- print("Part was touched")
local isHum = rot.Parent:FindFirstChild("Humanoid")
if isHum then -- cool, its a person of some sort
local Player = Players:GetPlayerFromCharacter(isHum.Parent)
if Player then -- we hit a player's character
print("This is a player!")
Player:DoSomethingWithThisCodeIDontKnowImNotTheCodeMaker()
end
end
end)
I would rather use teleportService:Teleport() instead. I know you stated that your current teleport script works before, but I believe it’s not done in the intended way. You see, TeleportAsync according to documentation reads
This function serves as the all-encompassing method to teleport a player or group of players from one server to another.
While it does say that it’s a method to teleport a player, it should be used for teleporting a group of players. Using this simple method would probably work better and take the weigh off your shoulder.
I’ve seen that you put quotes around Place ID making it a string. I am still somewhat inexperienced in Lua so I don’t know if that’s the case, but I find it kind of concerning that the brackets surrounds Player. Those are probably the main issues.
Try this.
local placeId = 0 -- Insert here, THIS IS NOT STRING, this is int
teleportService:Teleport(placeId, player) -- arg `player` is the `Player` class, it can be taken from Players.PLAYERNAME