New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
0

# Why isn't the ball coming to the player's position?

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

0
Why are you getting the mouse to check for a key? it is deprecated Thesquid13 301 — 3mo

0

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!

0
DONT USE INPUT BEGAN ON SOMETHING THAT ONLY NEEDS A CLICK Gameplayer365247v2 729 — 3mo
0
Thanks, it worked, but in what ways is UserInputService better? 50ShadesofLamps 5 — 3mo
0
For start, its not deprecated. Userinput service, as I said with the notes, you can control the button if the player is chatting, and also there are many functions, as InputBegan (when u pressed the key) or InputEnded (when you left it) EternalScythe 217 — 3mo