Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
sonuka 24
6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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)
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. sonuka 24 — 6y
0
Studio has a lot of bugs. Ton of them. HeComesAt_Night 116 — 6y
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. HeComesAt_Night 116 — 6y
0
By the way, if this is the answer you hoped for, press the answer button on this question. HeComesAt_Night 116 — 6y
View all comments (7 more)
0
Well I put it in a local script but it still doesn’t work ingame :/ sonuka 24 — 6y
0
Odd, let me try and find out. HeComesAt_Night 116 — 6y
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 sonuka 24 — 6y
0
I have solved it! HeComesAt_Night 116 — 6y
0
I have edited the answer. HeComesAt_Night 116 — 6y
0
Please put this as answered if the new edit helped. HeComesAt_Night 116 — 6y
1
Oh Thank you so much I will be trying it out now sonuka 24 — 6y
Ad

Answer this question