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

How do I fix this .Chatted Event Script?


game.Players.PlayerAdded:connect(function(player)
	game.Players.Chatted:connect(function(msg)
		if msg == "TeleUP" then
			function Tele(hit)
				if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
				game.LocalPlayer.Position = vector3.new(game.LocalPlayer.Position + vector3.new(0,50,0))
Tele()

				end
				
			end
		end
	end)
end)

I just found out how to use the .Chatted and I'm just having bit of trouble learning how to work it. So for practice I made this script but after testing it multiple times, I'm realizing it dosen't work. What I've been trying to do is, when you say the "Keyword" you'll teleport 50 units/studs (or whatever they're called) above from the spot you were at. I used my past experience with teleporting and did this script. How do I fix it? Thank you for the help.

3 answers

The reason it isn't working is not because of the .Chatted (that is fine), it is because of the function Tele(hit). hit.Parent is wrong and game.Players.LocalPlayer can't be used in a server side script. Try doing this instead:

function Tele()
	player.Character:MoveTo(player.Character.Torso.Position + Vector3.new(0, 50, 0))
end

This should work

game.Players.PlayerAdded:connect(function(player) -- Since you used player here, down below you can use it again, to get the player. No LocalPlayer
	game.Players.Chatted:connect(function(msg) -- 
		if string.lower(msg)  == string.lower("TeleUP") then -- You should use string.lower() otherwise they will have to say EXACTLY "TeleUP" with correct, EXACT capitalization. If you want that, change it back.
			--Did you NEED the function?
			player.Character.Torso.Position = player.Character.Torso.Position + Vector3.new(0,50,0) -- You need to use the players CHARACTER and you DON'T need to create a new vector3 with the values from the addition. The V in Vector3 should be capitial
		end
	end)
end)

The first function, PlayerAdded, makes it so that it can only work when they get added to the game. Remove that. Also, this is how to get a person's charctacter.

function Tele(hit)
hit.Parent.Character.Torso.Position = vector3.new(game.LocalPlayer.Position + vector3.new(0,50,0))
end
Tele()

1 comment

0

Wrong... When they get added it starts listening for .Chatted

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