script.Parent.MouseButton1Click:Connect(function(hit) hit.Position = Vector3.new(-18, 0.5, -9) end)
here's my code, it's very simple - I want the person who clicks the button to be teleported to the coordinates above. Am I misusing the event function?
MouseButton1Click does not have a parameter called hit that returns the player's character. You need to access the player's character by using game.Players.LocalPlayer.CharacterAdded: Wait()
. Here's an example:
local char = game.Players.LocalPlayer.CharacterAdded:Wait() script.Parent.MouseButton1Click:Connect(function() char.Position = Vector3.new(-18,0.5,-9) end)
This is only for use in a local script, which will not change anything for the server or the other players.
This is what you use for a normal (server) script:
game.Players.PlayerAdded:Connect(function(player) player.CharacterAdded:Connect(function(character) script.Parent.MouseButton1Click:Connect(function() character.HumanoidRootPart.CFrame=CFrame.new(Vector3.new(-18,0.5,-9) end) end) end)
This is what you are looking for. Am I correct?