Hello develepers, today i ran into a problem. I’m making a tycoon so, in the “cash register system” i need that only the owner of the tycoon can take the cash. every tycoon has a value called “Owner” it’s a number value and i put the Player’s id in that value.
this is the code for the “cash register”
Players.PlayerAdded:Connect(function(player)
script.Parent.Parent.Items.CashRecolector.Top.SurfaceGui.TextButton.MouseButton1Down:Connect(function()
if player.UserId == Values.Owner.Value and Values.Owner.Value == player.UserId then
if Debounce == false then
Debounce = true
script.Parent.Parent.Items.CashRecolector.Top.SurfaceGui.TextButton.BackgroundColor3 = Color3.fromRGB(213, 0, 0)
script.Parent.Parent.Items.CashRecolector.Top.Sound:Play()
player:WaitForChild("leaderstats").Money.Value += Values.CashValue.Value
wait()
Values.CashValue.Value = 0
wait(1)
Debounce = false
script.Parent.Parent.Items.CashRecolector.Top.SurfaceGui.TextButton.BackgroundColor3 = Color3.fromRGB(20, 204, 0)
end
else return
end
end)
end)
there is a line with an “IF” which says: if player.UserId == Values.Owner.Value and Values.Owner.Value == player.UserId then
here i check if the player who clicks is the owner of the tycoon so, after this, when i test with two people this is what happens:
The player at the left is the owner of the tycoon, he can take the money, no problem
The player at the right isn’t the owner of the tycoon. But as you can see, he can click the cash recolector and can take the money too.
Hi!
First of, you’re doublechecking here, meaning this is equivalent to
if GroupA == groupa and groupa == GroupA then
end
Change that to this:
local OwnerId = Values:FindFirstChild("Owner")
if OwnerId then
-- Also added a few prints:
print(Values.Owner.Value, player.UserId)
if player.UserId == OwnerId then
--Run your money code
end
end
Edit: And could you please tell me, why you have all this in a PlayerAdded function?
Hi!
Have you put a ClickDetector into your GUI on the board?
If so do this:
-- Insert this script into your clickDetector, or make 1 script that controls all the boards.
local ClickDetector = script.Parent
ClickDetector.MouseClick:Connect(function(Player)
-- Code here
end)
that’s what i tried mins ago, i don’t know why it doesn’t fire. i made a local script in a folder called scripts inside the TycoonModel
And also, it needs to be in the tycoon if i want it to work with only one script, so i can’t put the local script inside starter player scripts or something else…
Yep, that’s the problem all the scripts needs to be inside the tycoon model because if i don’t do that, i will need to reference every board of the tycoons. And what i want, is that you only need to copy one and tycoon, move it and that new tycoon that you cloned, works perfectly fine without doing anything. so i can’t do that.