Hi,
I have this issue with the code bellow. I keep getting the wrong player not the one who execute the event.
Do you have any thoughts?
-- Local Script Part
game.ReplicatedStorage.ev1.OnClientEvent:Connect(function(part)
game.ReplicatedStorage.ev2:FireServer(part)
end)
-- Server Script Part
game.ReplicatedStorage.ev2.OnServerEvent:Connect(function(player, part)
--code
--end
end)
-- Click Detector Part
function randomFunction(player)
self.parent:FindFirstChild("ClickDetector").MouseClick:Connect(function()
game.ReplicatedStorage.ev1:FireClient(player, self.clone.PrimaryPart)
end)
end
this feels like a troll post because of the obvious errors and unreasonable remoteevents unless you’ve had a sudden downgrade in coding ability since 2023…
you wouldn’t even be getting the wrong player because it’d error at self.parent
Those are the remote events not the main code. I get the wrong player when I execute my main code through the click detector, but the code is executing for other player not for the one executing it. Self is from oop I just put it as the example.
Don’t listen for a mouse detector click in the function, it will cause issues like the one you are describing. Move it outside of the other functions, it passes the player that clicked it as a parameter anyway.
Please don’t use self as an example variable here, unless you are actually doing OOP - it’s kind of confusing and misleading, I thought you were using a module for a second.
I am cloning some objects and each object has a click detector inside. I was forgetting to pass into the click detector the player argument. Now its working Thanks!
Actually I am using a module for both the click detector and the event from server side. I just commented above each code snippet what it is and I never said that the whole code is in one script.