Functions aren't working

hello! trying to make this code work but it isnt
code works by the player writing text in a text box ui
you click submit then code 1 goes into play
code issue:
code is printing the wrong thing when ran as a server script from a client script
code 1:


error 1:
image

code 2:


erorr 2:

code1 - local

local getstore = game:GetService("ReplicatedStorage")
local event = getstore:WaitForChild("JailData")

local reason = script.Parent.Parent.Reason
local offender = script.Parent.Parent.Offender
local ttime = script.Parent.Parent.Time

local reasonvalue = script.Parent.Reason
local timevalue = script.Parent.Time
local offendervalue = script.Parent.Offender

function leftClick(plr)
	reasonvalue.Value = reason.Text
	offendervalue.Value = offender.Text
	timevalue.Value = tonumber(ttime.Text)
	event:FireServer(plr, reasonvalue, timevalue, offendervalue)
	print(reasonvalue..offendervalue..tostring(timevalue))
end

script.Parent.MouseButton1Click:Connect(leftClick)

code2 - server

--This script takes the offenders username, time and reason and stores it in the data store 
--Then the jail manager script will take over with the data
local event = game:GetService("ReplicatedStorage")
local remote = event:WaitForChild("JailData")
local remote1 = event:WaitForChild("Jail")

local function datastoring(plr, reasonvalue, timevalue, offendervalue)
	print(tostring(plr).." has submitted data requests for ".. tostring(offendervalue))
	local player = game.Players:FindFirstChild(offendervalue)
	local reason = player.DataHost.jailHost.jailReason
	local ttime = player.DataHost.jailHost.jailTime
	reason.Value = reasonvalue
	ttime.Value = timevalue
	remote1:FireClient(offendervalue)
end

remote.OnServerEvent:Connect(datastoring)
1 Like

To fix Error 1, the problem is that ‘reasonvalue’ and ‘offendervalue’ are not strings, ‘reasonvalue.Value’ and ‘offendervalue.Value’ however are strings
Therefore, Line 17 should be replaced to

print(reasonvalue.Value..offendervalue.Value..tostring(timevalue))

To fix Error 2,
When you added :FireServer() in your local script, you added plr at the start but it is not needed because the plr argument is already given to the server by Roblox as the first parameter

This means that the ‘plr’ already provided by roblox to the server bumps all the parameters on the server to the right,
so
plr (Client) = plr (Server),
reasonvalue (client) = plr (Server),
timevalue (Client) = reasonvalue (Server),
offendervalue (client) = timevalue (server)
To fix this, remove plr from the :FireServer() like

event:FireServer(reasonvalue,timevalue,offendervalue)

But keep the plr in on the server, and your code should work

Sorry, if it was a bit long winded :+1:

1 Like

Okay error 1 is solved but information handler (code 2) now has this issue preposed:
image
Also with the prints the second one is supposed to print the offenders username (In my example I typed in ar_qx but it shows offender)
The first one I fixed dont worry
To clarify it shouldn’t print nil anywhere as there is always going to be data going in.

--This script takes the offenders username, time and reason and stores it in the data store 
--Then the jail manager script will take over with the data
local event = game:GetService("ReplicatedStorage")
local remote = event:WaitForChild("JailData")
local remote1 = event:WaitForChild("Jail")

local function datastoring(plr, reasonvalue, timevalue, offendervalue)
	print(tostring(plr).." has submitted data requests for ".. tostring(offendervalue))
	local player = game.Players:FindFirstChild(offendervalue)
	local reason = player.DataHost.jailHost.jailReason
	local ttime = player.DataHost.jailHost.jailTime
	reason.Value = reasonvalue
	ttime.Value = timevalue
	remote1:FireClient(offendervalue)
end

remote.OnServerEvent:Connect(datastoring)

yt on how it works:

1 Like

I think ‘offendervalue.Value’ is the player’s name, not ‘offendervalue’, as that is the object holding the value itself, therefore if you pass in ‘offendervalue.Value’ on the client to the server, instead of ‘offendervalue’, it should work

event:FireServer(reasonvalue,timevalue,offendervalue.Value)

So it seems like it still doesn’t work
error message - for code 2
image

code2 (server)

--This script takes the offenders username, time and reason and stores it in the data store 
--Then the jail manager script will take over with the data
local event = game:GetService("ReplicatedStorage")
local remote = event:WaitForChild("JailData")
local remote1 = event:WaitForChild("Jail")

local function datastoring(plr, reasonvalue, timevalue, offendervalue)
	print(tostring(plr).." has submitted data requests for ".. tostring(offendervalue))
	local player = game.Players:FindFirstChild(offendervalue)
	local reason = player.DataHost.jailHost.jailReason
	local ttime = player.DataHost.jailHost.jailTime
	reason.Value = reasonvalue
	ttime.Value = timevalue
	remote1:FireClient(offendervalue)
end

remote.OnServerEvent:Connect(datastoring)

code 1 (client)

local getstore = game:GetService("ReplicatedStorage")
local event = getstore:WaitForChild("JailData")

local reason = script.Parent.Parent.Reason
local offender = script.Parent.Parent.Offender
local ttime = script.Parent.Parent.Time

local reasonvalue = script.Parent.Reason
local timevalue = script.Parent.Time
local offendervalue = script.Parent.Offender

function leftClick(plr)
	reasonvalue.Value = reason.Text
	offendervalue.Value = offender.Text
	timevalue.Value = tonumber(ttime.Text)
	event:FireServer(reasonvalue,timevalue,offendervalue.Value)
	print(reasonvalue.Value..offendervalue.Value..tostring(timevalue.Value))
end

script.Parent.MouseButton1Click:Connect(leftClick)

yt: codeerrorpt2 - YouTube

1 Like

I just realized in my video I went to the wrong section I meant to go into playerGUI which shows the correct data:

1 Like

Ah, I think to fix this you need to change the reasonvalue to ‘reasonvalue.Value’ and timevalue to ‘timevalue.Value’ in the :FireServer() line

event:FireServer(reasonvalue.Value,timevalue.Value,offendervalue.Value)

1 Like

To solve error 1, it looks like offendervalue is a abojectValue so do this

offendervalue.Value.Name

To solve the second error, where you fire the remote, you are passing the offender value itself and not its actually value