Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Works in studio but How do I get this to work in real game?

Player is already defined but what do I do to make GetMouse work? The error I get is attempt to index local 'z'(a nil value).

local z = Player:GetMouse()
local v = Instance.new("BodyVelocity", Player.Character.UpperTorso)
v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
v.Velocity = z.hit.lookVector * 100

1 answer

✓ Accepted answer

The :GetMouse() Function only works in localscripts, if it is in one already, check any errors with the Player variable. | If this was the answer, please mark it as the answer so I can get more reputation so I can help others as well. [Edited Below]

------------~

The script also uses only R15 so it will not have any effect on R6 users.

I have fixed your line of code as well:

plr = game.Players.LocalPlayer
local z = plr:GetMouse()
loaded = false
plr.CharacterAdded:connect(function() --This triggers the loaded function to become true when character has loaded
	loaded = true
end)

repeat wait() until loaded == true -- This will wait and prevent any functions below from running until the loaded variable becomes true

plr.Character.Humanoid.Died:Connect(function() -- Changes variable back to false so it can restart the script.
	loaded = false
end)

z.Button1Down:connect(function()
	if loaded == true then -- This also makes sure the character is loaded before anything
local v = Instance.new("BodyVelocity")
v.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
v.Velocity = z.hit.lookVector * 100
v.Parent = plr.Character.UpperTorso
end
end)

11 comments

0

yea when I put it in local the script does work in studio but not in game :/ I also get no errors in game.

0

Studio has a lot of bugs. Ton of them.

0

Though, they had that error where it works with local script, but in game it only works with ordinary scripts for a while now.

0

By the way, if this is the answer you hoped for, press the answer button on this question.

0

Well I put it in a local script but it still doesn’t work ingame :/

0

Odd, let me try and find out.

0

Oh yea the game is FE I don’t know if thats the reason why it doesn’t work. I did use remote event though

0

I have solved it!

0

I have edited the answer.

0

Please put this as answered if the new edit helped.

1

Oh Thank you so much I will be trying it out now

This discussion is preserved as it was. New answers, comments, and votes are closed.