Hi! I am trying to work on a script that gets fired, then checks a table, and so on.
But, for some reason the script never gets fired. I put prints after it gets fired, and when it is fired. The prints for when it is fired, are printed. The prints after it gets fired, are never printed.
Any help?
The Firing script part
local Citation = script.Parent.Parent.Parent
local Suspect = Citation.Values.Suspect
local Reason = Citation.Values.Reason
local Infraction = Citation.Values.Infraction
print("localed")
game.ReplicatedStorage.TicketFired:FireServer(Suspect, Reason, Infraction)
print("fired")
The script fired
game.ReplicatedStorage.TicketFired.OnServerEvent:Connect(function(plr, Suspect, Reason, Infraction)
print("ok, got fired")
local PriceArray = {
["Dog Without Leash"] = 50,
["Disorderly Conduct"] = 150,
["Expired Vehicle Tag"] = 150,
--etc etc
}
print("pricearray")
Infraction = PriceArray[Infraction.Text]
-- HEre, you first get the Suspect's amount of money through te datastore or whatever. Save it as a local.
--Next, you'll deduct the players cash using the PriceArray above, do that by using Suspect.Cash.Amount = PriceArray[Infraction.Text]
print(Infraction)
game.ReplicatedStorage.TicketFired:FireAllClients(plr, Suspect, Reason, Infraction)
print("fireallclients")
end)
Are you sure the server script runs? Put a print in the 1st line of it. Make sure to parent it to Workspace or ServerScriptService, as @Dandystan suggested
General architecture for client to server communication (comms as I abbreviate it) is tricky, hella tricky to debug too.
I hate to be that guy, but is your firing script part a Localscript?
Where are both of your scripts?
Note: (The script being in startercharacterscripts is fine, just means the script will run on every player’s character)
I’m just theorizing here, but you might be able to do it like that. You’d be able to clone the LocalScript to the player, and then you would be able to fire the event.
For your local script, you need to confirm that the events are, in fact, there when the script runs (though this probably isn’t your error if you haven’t seen anything in the output).
To do this, you would need to get ReplicatedStorage and wait for your TicketFired event.
local TicketFired = game:GetService("ReplicatedStorage"):WaitForChild("TicketFired")
Using game:GetService(“SERVICE_NAME”) is generally better practice than using game.SERVICENAME, as with :GetService() if you’ve changed the name of the service object then it still works, however the latter would break.
This isn’t need for the server-side script within ServerScriptService.
EDIT: This is wrong, please refer to here and here where I got the information for this post (they were edited)
Would you care to share your fixed code with us?
It might help someone else who has a similar problem and the solution would save them having to raise another topic.