For some rason this works well on solo but on a server I keep getting a error saying:
Workspace.Model.Screen.Game.Game.Controls:13: attempt to index local 'PlayersMouse' (a nil value)
Oh and the script is just a regular one not local.
why did I get this error and how do I fix it?
local BlueBar = script.Parent.GAME.BluPdl
local RedBar = script.Parent.GAME.RedPdl
local BlueSeat = script.Parent.Parent.Parent.Parent.BlueSeat
local RedSeat = script.Parent.Parent.Parent.Parent.RedSeat
----------------------BlueSeat----------------------------
BlueSeat.ChildAdded:connect(function(Part)--Checks if a Player has been steated
if Part.Name == "PlatformMotor6D" and Part.Part1.Name =="Torso" then
---------------------Vairbles-------------------------
local Character = Part.Part1.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local PlayersMouse = Player:GetMouse()
------------------------------------------------------
BlueSeatConnection = PlayersMouse.KeyDown:connect(function(Key)
if Key == "w" then
if BlueBar.Position.Y.Offset > 0 then -- Rise Up if pressed w
BlueBar.Position = UDim2.new(0, 0, 0, (BlueBar.Position.Y.Offset - 20))
end
elseif Key == "s" then
if BlueBar.Position.Y.Offset < 400 then
BlueBar.Position = UDim2.new(0, 0, 0, (BlueBar.Position.Y.Offset + 20))
end
BlueSeat.ChildRemoved:connect(function(Part)
if Part.Name == "PlatformMotor6D" and Part.Part1.Name =="Torso" then
BlueSeatConnection:disconnect()
end
end)
end
end)
end
end)
----------------------RedSeat------------------------------
RedSeat.ChildAdded:connect(function(Part)--Checks if a Player has been steated
if Part.Name == "PlatformMotor6D" and Part.Part1.Name =="Torso" then
---------------------Vairbles-------------------------
local Character = Part.Part1.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local PlayersMouse = Player:GetMouse()
------------------------------------------------------
RedSeatConnection = PlayersMouse.KeyDown:connect(function(Key)
if Key == "w" then
if RedBar.Position.Y.Offset > 0 then
RedBar.Position = UDim2.new(0, 560, 0, (RedBar.Position.Y.Offset - 20))
end
elseif Key == "s" then--Rise down if s is pressed
if RedBar.Position.Y.Offset < 400 then
RedBar.Position = UDim2.new(0, 560, 0, (RedBar.Position.Y.Offset + 20))
end
RedSeat.ChildRemoved:connect(function(Part)
if Part.Name == "PlatformMotor6D" and Part.Part1.Name =="Torso" then
RedSeatConnection:disconnect()
end
end)
end
end)
end
end)

1 comment
You MUST use GetMouse() in a local script.