local m = game.Players.LocalPlayer:GetMouse() m.KeyDown:Connect(function(key) if key == "x" then print("hi") game.Workspace.Hamster.Position = game.Players.LocalPlayer.Character.Position end end)
so what it is supposed to do is teleport a the Union(Hamster) to the players location when x is pressed
Hi is not printed when I press x but if I remove
game.Workspace.Hamster.Position = game.Players.LocalPlayer.Character.Position
hi will be printed
Well, for start, DONT USE KEYDOWN. It's deprecated. Use UserInputService, now with the main problem, it's not coming because character is a model, and not a part, that means it doesnt got "position" itself. Instead of that script, Use this:
local Hamster = workspace.Hamster local player = game.Players.LocalPlayer local char = player.Character game:GetService("UserInputService").InputBegan:Connect(function(input, gameEvent) if input.KeyCode == Enum.KeyCode.X and not gameEvent then print("X fires.") Hamster.Position = char.HumanoidRootPart.Position -- I assume "Hamster" is a part, if its another model it wont work. end end)
Here are some notes:
-As you did this in a local script, the hamster will be only visible for you, and not for the people around, if you want other people to see it, you have to fire a remote.
-Please, Never use deprecated things such as KeyDown. UserInputService is quite better.
-The second parameter of UserInputService "gameEvent" is if the player is writing on the chat and it press they key, so that means, if the player press they key and is not on the chat the function will fire.
I hope I helped, any question comment me (also it would be nice if u upvote) now, bye!