Okay so, I am trying to make a funcion that teleports you whenever you say: “/tower” it will teleport the user to the part that is near the tower i made in my game, the tower is irrelevant but for more context.
Here is the code I made
local player = game.Players.LocalPlayer
local endpart = workspace.Part
game.Players.PlayerAdded:Connect(function()
player.Chatted:connect(function(msg)
msg = msg.lower()
if msg == "/tower" then
player.HumanoidRootPart.Position = endpart.Position
end
end)
end)
And there was a error, here:
So if you are a experienced Scripter and know how to fix this, leave a reply with the solution. Thanks!
PS: I titled myself a builder, since I am still practising coding, and not a really good one yet.
First you need to pass the player as one of the arguments for the chatted event to recognize who even chatted, Second of all you need to get the character to call any child of that player’s character
for instance:
player.Character:WaitForChild("Torso")
Also, I’d suggest getting used to :Connect() as it looks more neat
Simple, You’re calling the variable the same name as the argument passed in the event simply change the name of the variable to something else like LowerMessage and such, Hopefully I helped if not reply to this and I’ll get back as soon as possible
This might seem like “SpoonFeeding” but I’m not the best with explaining so here you go
local endpart = workspace.Part
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local loweredMessage = msg.lower()
if loweredMessage == "/tower" then
player.Character.HumanoidRootPart.CFrame = CFrame.new(endpart.Position)
end
end)
end)
local endpart = workspace.Part
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
local tpmessage = string.lower("/tower")
if msg == tpmessage then
player.Character.HumanoidRootPart.CFrame = endpart.CFrame
end
end)
end)