Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Make My Own Service?

Asked by 9 years ago

I Want To Make My Own Service. But I Don't How.

I Tried This:

game.Workspace=Instance.new("J Player Service")

Help Me.

0
I don't think you can fahmisack123 385 — 9y
0
Wait is this even possible? IF IT IS I WANNA KNOW!!!! ZeptixBlade 215 — 9y
0
You can Insert a new service into your game, but you can not created your own service, only ROBLOX is able to create new services, because, they scripted out special coding for them, you would be having trouble if you tried to make one. TheeDeathCaster 2368 — 9y

3 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

ROBLOX doesn't allow you to create new classes of objects (because these objects are implemented in C, not in Lua)

This applies to services, too.


There isn't any good reason to want to create a new class of ROBLOX object.


While there aren't any generic containing objects, any object may be used to contain any other, so the want of a lack of extra functionality isn't very significant.

Using a Model instance or a Script or some other class is sufficient for creating your own namespace.

You are allowed to parent objects to the DataModel (game):

Instance.new("Model", game).Name = "LikeAService";

Instance.new("Part", game.LikeAService)
print( #game.LikeAService:GetChildren() )

Though there might be bad effects from doing this. It would be better to store this in ReplicatedStorage or ServerStorage or the Workspace.


If you aren't actually interested in storing ROBLOX objects, then you probably just want to define a ModuleScript or define functions in _G. Alternatively, use BindableFunctions, RemoteFunctions, RemoteEvents, etc., to implement custom functionalities.

0
Oh. Thanks! JlintGod 0 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

First thing, if you could make your own service that would error out Second, You cant make your own service.

Now I think I understand what your wanting to make...

its a service like

~~~~~~~~~~~~~~~~~ game.Players:GetPlayers()

 BUT... there is no way on Roblox to make you own service.
but for this just use 
This will return and find all the Players in the current game EXAMPLE : 

for _, Plrs in pairs(game.Players:GetPlayers()) do Plrs:LoadCharacter() end ~~~~~~~~~~~~~~~~~

Now all the players will be respawn automaticaly

Log in to vote
0
Answered by 3 years ago

Sorry for the late reply, but for anyone else out there looking: its easy! It isn't gonna be exactly like Instance.new() sorta thing, but it'll be you're own library! Lets begin!

First off, you need to remember to have something in your library, or it won't do anything. So lets make a module to be your first service

HelloWorld <module script>

local HelloWorld = {}

HellowWorld.print = function()
    print("Hello World!");
end

return HelloWorld;

Lets set up our create script. This will act as a fill in for our missing Instance.new, since Roblox is using it.

Create <module script>

local create = {
    PingPong = {
        create = function(args)
            local ping = {};
            t_pongged = Instance.new("BindableEvent");
            ping.Ping = function() 
                print("Pong");
                t_pongged:Fire(); --This will trigger our ping.Pongged event.
            end         
            ping.Pongged = t_pongged.Event; --We store .Event here so they view it as Ping.Pongged:Connect();
            return ping;
        end
    }
}

return create;

Now its time to set up our library! Just like how roblox has game, we'll have our own library!

library <module script>

local t_create = require(Create);
local library = {
    HelloWorld = require(HelloWorld);
}

function library:GetService(Service) --I don't have to explain this to you.
    return library[Service];
end

function library:Create(ClassName) --This will act as our replacement for Instance.new()
    local class = t_create[ClassName].create(args);
    return class;
end

Lets try it out!

script

local library = require(libraryModule);

local HelloWorld = library:GetService("HelloWorld");

local Class = library:Create("PingPong");
Class.Pongged:Connect(function(args)
    print("Ping!");
end)
Class.Ping();

HelloWorld.print();

Now that you know this, I'm pretty sure you can make whatever you want

Answer this question