Hello all,
I’m sort of new to OOP with Lua and was messing around with OOP using values in a character. Using a players mouse they could change certain values (you can see in the module script). It works great with one player, but when I go to two or more players the script updates the values for all players.
No errors in output or anything.
Only other post I could find with a related issue is this one.
Module Script:
local ControllerFramework = {}
ControllerFramework.__index = ControllerFramework
function ControllerFramework.new(Player, Team)
local self = setmetatable({}, ControllerFramework)
self.Player = Player
self.NPCCheck = Player.Character.Values.ClickedOnNPCCheck.Value
self.NPCObject = Player.Character.Values.ClickedOnNPCObject.Value
self.Team = Team
return self
end
function ControllerFramework:MouseClicked(MouseTarget)
print(self.Player)
if MouseTarget ~= nil then
if MouseTarget.Parent:FindFirstChild("Humanoid") and not self.NPCCheck then
self.NPCCheck = true
self.NPCObject = MouseTarget.Parent
print("ClickedOnNPC")
elseif MouseTarget.Parent:FindFirstChild("Humanoid") and self.NPCCheck and self.NPCObject == MouseTarget.Parent then
print("Unclicked on NPC")
self.NPCCheck = false
self.NPCObject = nil
elseif MouseTarget.Parent:FindFirstChild("Humanoid") then
self.NPCObject = MouseTarget.Parent
print("ClickedOnAnotherNPC")
else
print(MouseTarget)
end
end
end
return ControllerFramework
Script (I’m not sure if the error is in here):
local RemoteFunc = game.ReplicatedStorage.Events.RemoteFunction
local RemoteController = require(game.ServerScriptService.ModuleScript)
local Character = script.Parent
local Player = game.Players:GetPlayerFromCharacter(Character)
local Gun = RemoteController.new(Player)
RemoteFunc.OnServerInvoke = function(Player, MouseClickedPosition)
print(Gun)
Gun:MouseClicked(MouseClickedPosition)
end