Value not working through server script in remote event

Hello, I am working on a arrest system and I am very confused on why this isn’t working. It seems like the parent for the case folder isn’t working. I think it is because the prisoner value isn’t going through correctly. I have tried to send it back to the client and print it, and it prints off the value, and when I remove game.Workspace.Players:FindFirstChild(Prisoner).Arrests and just put it as Game.Workspace it works fine. I am very confused.

Server script:

game.ReplicatedStorage.Arrested.OnServerEvent:Connect(function(player, reason, prisontime, Prisoner)
	local case = Instance.new("Folder")
	local reasons = Instance.new("StringValue")
	local timer = Instance.new("NumberValue")
	local arrestingofficer = Instance.new("StringValue")
	case.Name = "Case #"..math.random(1000,100000)
	case.Parent = game.Workspace.Players:FindFirstChild(Prisoner).Arrests

	reasons.Name = "Reason"
	reasons.Value = reason
	reasons.Parent = case
	timer.Name = "SetTime"
	timer.Value = prisontime
	timer.Parent = case
	arrestingofficer.Name = "ArrestingOfficer"
	arrestingofficer.Value = player.Name
	arrestingofficer.Parent = case
end)

Local script’s fire event

game.ReplicatedStorage.Arrested:FireServer(frame:WaitForChild("ReasonBox").Text, frame:WaitForChild("PrisonTimeBox").Text, game.Players:GetPlayerFromCharacter(mouse.Target.Parent))

Have you tried fail saving the values? Reason and officers values need to be strings, and the time needs to be a number, so you could try doing

reasons.Value = tostring(reason)

timer.Value = tonumber(prisontime)

arrestingofficer.Value = tostring(player.Name)

Also, if this is something thats going to be saved in a datastore, be careful with the random case number generation! You’re bound to eventually end up with two cases with the same number and it MIGHT break some things

I think it maybe because you are trying to send a object(a player) from the client to the server
then trying to use findfirstfirst child on the wrong folder
Players is part of game not workspace

players

also as jonibus showed use tonumber on your time since you send over as string

game.ReplicatedStorage.Arrested.OnServerEvent:Connect(function(player, reason, prisontime, PrisonerName)  -- use the PrisonerName  name of that player get play inside this function
	local Prisoner = game.Players:FindFirstChild(PrisonerName)   -- get the player for that prisoner name
	if not Prisoner then print('NotFoundPrisoner ', PrisonerName )return end  -- if it didn't find a player with this name just exit function
local ArrestsFolder = Prisoner:FindFirstChild('Arrests')
if not ArrestsFolder  then print("Player Doesn't have ArrestsFolder ", Prisoner) return end
	local case = Instance.new("Folder")
	local reasons = Instance.new("StringValue")
	local timer = Instance.new("NumberValue")
	local arrestingofficer = Instance.new("StringValue")
	case.Name = "Case #"..math.random(1000,100000)
	case.Parent = ArrestsFolder 

	reasons.Name = "Reason"
	reasons.Value = reason
	reasons.Parent = case
	timer.Name = "SetTime"
	timer.Value = tonumber(prisontime)   -- you will need tonumber here since you are sending it over as string
	timer.Parent = case
	arrestingofficer.Name = "ArrestingOfficer"
	arrestingofficer.Value = player.Name
	arrestingofficer.Parent = case
end)

on your local you need to just send over prisonername

local Prisoner = game.Players:GetPlayerFromCharacter(mouse.Target.Parent)  -- i would set it like this 
if not Prisoner then return end  -- and return if no player is set by it
game.ReplicatedStorage.Arrested:FireServer(frame:WaitForChild("ReasonBox").Text, frame:WaitForChild("PrisonTimeBox").Text, Prisoner.Name)

I have also tried to put a value from a string value instead of the player earlier and it still didn’t work.

I forgot the Arrests on Prisoner there so i added it as a variable also to see if its under player or not
to me from what you said above you are not creating the Arrests folder in each player you are just creating one in the workspace which would be why its fine on game.workspace

Ok there had to edit it should be good now you can see how it checks for the folder and will tell you if the player has it or not

For some reason server scripts do not print things but I can see in the explorer that it didn’t go into the folder in testing.

where is the folder?

and it should print in studio for server
and if you are in actual game press F and then click the Server button … may have to toggle output on that sometimes it bugs

The folder is no where since it was not able to be assigned a parent.

You should make sure you are creating and parenting an arrestfolder to each player and it should work

I am parenting it but it is getting the prisoner value as nil I believe

right on your local script if your prisoner is being set to a player send over the name not the object else it may go as nil sometimes you can’t pass objects from client to server if I remember right

in the above script for local it sends over name then on server it gets that player again

you can also use Print to debug this like on local print the prisoner print(Prisoner) – this will make sure you are getting something set to the variable
then on server do the same print(PrisonerName) – which lets you know that string came over
then your Prisoner server side so print(Prisoner) – which should be the prisoners player object – this is actually done in the line below that is there if it is nil and tells you

just make sure if your prints are in loops to remove after you debug
prints are friends when debugging for sure