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:
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)
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
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
Okay error 1 is solved but information handler (code 2) now has this issue preposed:
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)
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
So it seems like it still doesnât work
error message - for code 2
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)