Hello!
In my script it says attempting to index nil with ‘GetMouse’ I was trying to fix it and i failed, can someone pls fix it
local chips = script.Parent
local Mouse = player:GetMouse()
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local function colorChange(player)
wait(2)
local char = player.Caracter or player.CharacterAdded:Wait(0)
if char then
chips["Body Colors"].Parent = char
wait(1)
char:Destroy()
end
end
if chips.Enabled == true then
Mouse.Button1Down:Connect(colorChange(player))
end
local Mouse = player:GetMouse()
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent
you didnt define ‘player’ before : GetMouse () and define ‘player’ after
here is the fixed code :
local chips = script.Parent
player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local Mouse = player:GetMouse()
local function colorChange(player)
wait(2)
local char = player.Caracter or player.CharacterAdded:Wait(0)
if char then
chips["Body Colors"].Parent = char
wait(1)
char:Destroy()
end
end
if chips.Enabled == true then
Mouse.Button1Down:Connect(colorChange(player))
end
it does not work. I tried with your script, but it does not matter if you use mine or yours because its a global variable. I didn’t put local befor it.
local chips = script.Parent
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local Mouse = player:GetMouse()
local function colorChange(player)
wait(2)
local char = player.Character or player.CharacterAdded:Wait(0)
if char then
chips["Body Colors"].Parent = char
wait(1)
char:Destroy()
end
end
if chips.Enabled == true then
Mouse.Button1Down:Connect(colorChange(player))
end
Hello! I see you’re having trouble with your script. It looks like the issue is that you’re trying to use the GetMouse method on a player variable that hasn’t been defined yet. You should move the line local Mouse = player:GetMouse() below the line where you define the player variable.
Here’s an example of how you could fix your script:
local chips = script.Parent
local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)
local Mouse = player:GetMouse()
local function colorChange(player)
wait(2)
local char = player.Character or player.CharacterAdded:Wait()
if char then
chips["Body Colors"].Parent = char
wait(1)
char:Destroy()
end
end
if chips.Enabled == true then
Mouse.Button1Down:Connect(function() colorChange(player) end)
end
“In my script it says attempting to index nil with ‘GetMouse’ I was trying to fix it and i failed” - Don’t worry, we all make mistakes when coding. The important thing is to keep trying and learning from our mistakes!