Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Need help printing on roblox server to local?

So for example I want to print something out of serverstorage correct but instead of it printing on the servers console I want it to print on the local players console I had a few methods but idk if im right so im here now what i got so far.

Player = game.Players["Player"] H = Instance.new("StringValue") H.Parent = Player for i,v in pairs(game.ServerStorage[".stats"]["Player"]:GetChildren()) do H.Value = v.Name end

3 comments

0

Use a block quote please. :)

0

No, use a CodeBlock.

0

Sorry, was tired, thats what I ment. :3

1 answer

The simplest way to do this is to use a remote function as this will also work with fe. This will allow us to send the string names of what the processing finds. We cannot send the objects unless both sides have access to them e.g. parts in the workspace.

Example using remote functions:-

-- setup of the remote function
local remoteFunction = Instance.new('RemoteFunction', game:GetService('ReplicatedStorage'))
remoteFunction.Name = 'test'

function remoteFunction.OnServerInvoke(plr, getChildren, ...)
	local args = {...} -- ... indicates variable number of arguments
	
	-- check length
	if #args == 0 then return {'No args passed'} end
	
	local tmpTabl = {}
	local tmpData = game -- we start at game but we could start at another place 
	
	for i=1, #args do
		if tmpData:FindFirstChild(args[i]) then -- loop and try to get each child
			tmpData = tmpData:FindFirstChild(args[i])
		else
			-- we found a nil
			return {'Endpoint is nil'}
		end
	end
	
	if getChildren then
		for _, v in pairs(tmpData:GetChildren()) do -- get all children
			table.insert(tmpTabl, tostring(v))
		end
	else
		table.insert(tmpTabl, tostring(tmpData))
	end
	
	-- return result to the local script
	return tmpTabl
end

Local script example:-

local remFunc = game:GetService('ReplicatedStorage'):WaitForChild('test')

print('from server', unpack(remFunc:InvokeServer(false, 'Workspace','Part')))
print('from server', unpack(remFunc:InvokeServer(true, 'Workspace','Part')))
print('from server', unpack(remFunc:InvokeServer(true, 'ServerStorage','Padasd')))
print('from server', unpack(remFunc:InvokeServer(true, 'ServerStorage','Part')))

This is just my test setup.

You can also send the logs to the client. This would also use the same method of a remote function to pass back the logs to the client.

I hope this demo shows how this can be used. You should be able to adapt and change this to provide the functionality you need.

Please comment if you do not understand how / why this code works.

This discussion is preserved as it was. New answers, comments, and votes are closed.