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)
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
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 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
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
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