Any tips on how to fix? I’ve tried everything…
(Doesn’t output any errors)
game.ReplicatedStorage.PoliceEvents.SendCitation.OnServerInvoke = function(Officer,Player,Reason,Amount)
if not Officer.PlayerGui:FindFirstChild('Citation') then return end
if Amount <= 0 then return end
local Suspect = game.Players:FindFirstChild(Player)
print(Amount) -- This prints out the right amount
print(Reason) -- Prints out the correct reason
Suspect.Stats.Money.Value = Suspect.Stats.Money.Value - Amount
local Ticket = game.ServerStorage:FindFirstChild('Cited'):Clone()
Ticket.Parent = Suspect.PlayerGui
Ticket.Frame.Amount.Text = Amount -- Displays 'TextLabel'
Ticket.Frame.Reason.Text = Reason -- Displays 'TextLabel'
Ticket.Frame.plr.Text = Suspect.Name
Ticket.Frame.OFC.Text = Officer.Name
--
end
Something I want to point out firsthand - it doesn’t look like you have any server-side verification. This is a dangerous situation, especially when you seem to be accepting custom values from the client. This is easily exploitable and someone can have their cash swiped immediately. Checking for an existing UI is not a smart strategy either, you shouldn’t have any server-code interacting with the PlayerGui.
Another issue is that you’re parenting a Gui to another player and then attempting to edit it. You can’t do this. Instead, what you should have the server do is send this data to the client and have the client create their own “you’ve been cited” UI.
For starters, in case you haven’t a clue what I just said, move the line “Ticket.Parent = Suspect.PlayerGui” below everything. It’s generally good practice to set properties first before the parent.
No, I will worry about security and so should you. This is a vulnerable system and has holes to be exploited from. If an exploiter has the UI, they can do as they so please. You also should not be using the server to check for existing UIs on the client. UI work should always remain on the client and the server should be validating input or requests sent from the client.
if not Officer.PlayerGui:FindFirstChild('Citation') then return end
if not Officer:IsInGroup() then return end
if Amount <= 0 then return end
In my case, this is enough security. as anyone who isn’t in the Police Department won’t be able to send Citations - and it checks if the player has the UI, if not then nothing happens