How to get module script to run on client and server side

So I have a function in a module script that is supposed to make a planet, but the planet is only generating in server side, So how do i make that it generates in server and client side at the same time?

local module = {
	GeneratePlanet = function(size: number, atmospehere: boolean, temp : number, moons: number, type: string)
		print("Atmospehere: "..tostring(atmospehere))
		local part = Instance.new("Part")
		part.Anchored = true
		part.Parent = workspace.Object
		part.Shape = Enum.PartType.Ball
		part.Position = Vector3.new(5000, 200, 0)
		part.Size = Vector3.new(size, size, size)
		part.Color = Color3.fromRGB(math.random(1,255),math.random(1,255),math.random(1,255))
		local materials = Enum.Material:GetEnumItems()
		part.Material = materials[math.random(#materials)]

		if atmospehere == true then
			print("Statement running")
			local part2 = part:Clone()
			part2.Material = Enum.Material.ForceField
			part2.Parent = part
			local mesh = Instance.new("SpecialMesh")
			mesh.MeshType = Enum.MeshType.Sphere
			mesh.Parent = part2
			mesh.Scale = Vector3.new(1.1,1.1,1.1)
		end
	end

	
}

return module

You can use a RemoteEvent to fire to the client that you made a planet, and just replicate it.

But theres no need tbh as everything that is done on the server is replicated onto the client.

Also the way this module is organised is horrible and unreadable, at least do:

return {} -- Your function here

But its better do do everything outside the table as indexes instead of this.

Well, I’m new to module scripts and the module script in ServerScriptService when adding a part on server doesn’t add it on client for some reason

Weird.

Well ig just use Remote Events. But that’s interesting that it doesn’t replicate.

Ig you can also do:

game:GetService(“RunService”):IsServer()

or

game:GetService(“RunService”):IsClient()

but idk.

That is super dumb, running a module script on the server and on the client with the same functionality is useless

I think i know what the issue is, please open up your Studio and go into your place.

After you did that go to game.Workspace and find the property StreamingEnabled and change it to false
Screenshot 2025-03-21 200723

1 Like

That is a common problem that is caused by rendering issues, you see if the player isn’t anywhere near a part or simply cant see it roblox won’t render it and you won’t be able to see it on the client. That’s why StreamingEnabled exists, it allows you to turn off that rendering and make those parts / instances visible

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.