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

how can i fix this teleport taht wont work ?


local player = game.Players:GetPlayerFromCharacter(hit.Parent)

player.Character.Torso.CFrame = CFrame.new(Vector3.new(192.713, 7.374, -898.129))

end)

heres the error

11:26:38.627 - Stack End 11:26:38.629 - Torso is not a valid member of Model 11:26:38.630 - Stack Begin 11:26:38.632 - Script 'Workspace.Part.Script', Line 5 11:26:38.634 - Stack End 11:26:38.667 - Workspace.Part.Script:5: attempt to index local 'player' (a nil value) 11:26:38.671 - Stack Begin 11:26:38.674 - Script 'Workspace.Part.Script', Line 5 11:26:38.676 - Stack End

4 comments

0

its really not that hard to read

0

also unless you're blind thats a code block

0

That's not a code block, look at my answer to see a code block.

0

You're using code blocks incorrectly.

1 answer

✓ Accepted answer

Sorry to say but almost every single line here is improper. I'll rewrite the script and do my best to explain what happened as best as I can.

script.Parent.Touched:connect(function(hit)
	local humanoid = hit.Parent:FindFirstChild('Humanoid')
	if humanoid then
		hit.Parent.HumanoidRootPart.CFrame = CFrame.new(192.713, 7.374, -898.129)
	end
end)

So the first thing I want to point out is the touched event. You'll want to have this if statement here to make sure the thing touching the part is a player and not another part.

local humanoid = hit.Parent:FindFirstChild('Humanoid')
if humanoid then
	-- Script stuff
end

Also, touched events detect the character, not the player. So instead of doing GetPlayerFromCharacter() (This line here is completely messed up anyways, it would take forever to explain) you can just access the character through the hit.Parent.

Lastly, the HumanoidRootPart is the PrimaryPart for the character. You'll always want to use CFrame and not Vector3 when teleporting the player.

I've tested this script and it works perfectly. Enjoy!

1 comment

0

thankst

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