Hi there everyone, I have an issue with the
player:GetMouse() function.
It seems to overwrite player object if referenced in any function being passed through the
Mouse.Button1Down:Connect([functionName])
line.
Here is my code:
local Mobius = require(game.ReplicatedStorage.Monkey.Core.Mobius)
local Pieces = require(game.ReplicatedStorage.Monkey.Core.Pieces)
local DeckList = require(game.ReplicatedStorage.Monkey.Items.DeckList)
local player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
local MetaData = Mobius.new(workspace:WaitForChild("MetaData"):GetChildren())
local UpdateSelectionEvent = game:GetService("ReplicatedStorage").Events.UpdateSelection
local MovePiece = game:GetService("ReplicatedStorage").Events.MovePiece
local function isTilePart(part)
return string.sub(part.Name, 1, 4) == "Tile"
end
local function Select()
for _, items in ipairs(DeckList) do
if tostring(Mouse.Target) == items.Name and Mouse.Target.Parent == workspace:WaitForChild(player.Name) then
UpdateSelectionEvent:InvokeServer(tostring(Mouse.Target))
end
end
end
print(MetaData:GetPlayerSelection(player))
local function MoveTarget()
if isTilePart(Mouse.Target) then
print(player:GetChildren())
if MetaData:GetCurrentPlayer() == player.Name and MetaData:GetPlayerTurns(player) > 0 and MetaData:GetPlayerSelection(player) ~= nil then
MovePiece:InvokeServer(MetaData:GetPlayerSelection(), Mouse.Target.Position)
end
end
end
Mouse.Button1Down:Connect(Select)
Mouse.Button1Down:Connect(MoveTarget)
Pay attention to the
local function MoveTarget()
if isTilePart(Mouse.Target) then
print(player:GetChildren())
if MetaData:GetCurrentPlayer() == player.Name and MetaData:GetPlayerTurns(player) > 0 and MetaData:GetPlayerSelection(player) ~= nil then
MovePiece:InvokeServer(MetaData:GetPlayerSelection(), Mouse.Target.Position)
end
end
end
Function.
It is trying to verify the current turn (in the game) is the player clicking, if they have the right amount of turns, and if the player’s selection value isn’t empty.
Mobius module:
local Mobius = {}
function Mobius.new(metadata)
local self = setmetatable({}, {__index = Mobius})
self.metadata = metadata
return self
end
function Mobius:GetCurrentPlayer()
for i,v in pairs(self.metadata) do
if v.Name == "CurrentTurn" then
return v.Value
end
end
end
function Mobius:GetPlayerSelection(player)
if player then
print("Player exists")
local currentSelection = player:WaitForChild("CurrentSelection")
return currentSelection.Value
else
print("player doesn't exist")
end
end
function Mobius:GetPlayerTurns(player)
if player:FindFirstChild("Turns") then
return player["Turns"].Value
end
end
function Mobius:ChangeCurrents(player, newValue)
if player:FindFirstChild("CurrentSelection") then
player["CurrentSelection"].Value = tostring(newValue)
end
end
return Mobius
At first when clicking, it returns true. The player does exist. But half a second later it returns false, the player doesn’t exist. Any clue as to why?