✓ Accepted answer
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
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!
1 comment
Why are you getting the mouse to check for a key? it is deprecated