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

How do I make a client-side model into a server-side model?

Asked by 5 years ago

I have this local script that copies the "Model" object class. The only problem is that the cloned model is local, which means only the player who cloned the model can see it. How do I make the cloned model something that can be seen server wide?

If this code is unfixable, then is there anything that I should know about making backpack tools work with the rest of the server?

function select(mouse)
mouse.Button1Down:connect(function()
    if mouse.Target~=nil then    
        if mouse.Target.Locked==false then    
        if mouse.Target.Parent.ClassName=="Model" then    
        clone=mouse.Target.Parent:clone()    
        clone.Parent = workspace    
        mouse.TargetFilter=clone    
    end    
    end    
end   
end)  
mouse.Move:connect(function()    
if clone~=nil then    
    clone:MoveTo(mouse.Hit.p)    
end    
end)    
mouse.Button1Up:connect(function()    
    clone=nil    
end) 

end   
script.Parent.Selected:connect(select)

If you read through this, thank you for your time.

0
I don't think you can. Even through sending it to the server via RemoteEvents, the model stays local. DeceptiveCaster 3761 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

I think what you would have to do there is use a RemoteEvent and right where you're cloning the tool, instead call a FireServer function and have a script on the server do that part. This is something I'm struggling with figuring out as well. If you then have a script on the server create it in that player's backpack, does the tool exist locally or on the server? I would think it would be on the server and would be visible to all clients, but you'd have to test it to find out. If you do try this, lemme know what results you get.

0
It would still be local. DeceptiveCaster 3761 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Use remote events.

Here's a example script.

Client:

local Players = game:GetService("Players")
local Local_Player = Players.LocalPlayer
local ModelNumber = 0
local Model = PathToTheModel
local Replicated_Storage = game:GetService("ReplicatedStorage")
local Remote_Event = Replicated_Storage:WaitForChild("RemoteEvent")

function MakeModel()
    ModelNumber = ModelNumber + 1
    local X = Model:Clone()
    X.Name = "ClientModel"
    X.Parent = workspace
    Remote_Event:FireServer(ModelNumber)
    workspace:WaitForChild("ServerModel"..Local_Player.Name..ModeNumber)
    X:Destroy()
end
--// Fire the event whenever you want to create a model.

Server:

local Replicated_Storage = game:GetService("ReplicatedStorage")
local Model = PathToTheModel
local Remote_Event = Instance.new("RemoteEvent")
Remote_Event.Name = "RemoteEvent"
Remote_Event.Parent = Replicated_Storage

Remote_Event.OnServerEvent:Connect(function(player, modelnumber)
    local X = Model:Clone()
    X.Name = "ServerModel"..player.Name..modelnumber
    X.Parent = workspace
end)

This code will first create the model in the client, while firing a remote event to the server to create the model in server. This is meant to make the effect that it is instant. Anything else is self explanatory, it clones a model and then parents it to workspace, as this is what I assumed is what you're attempting to do. Please note that this code doesn't have any protection and is not secure, please make it more secure and have some kind of a exploiter prevention as otherwise exploiters can just abuse it. This is just example code.

Sorry if this example code errors, I haven't tested it. But that should give you a good idea of what you can do. I'm terrible at explaining things, so here's a tutorial for remote events if you are interested in learning more. https://www.youtube.com/watch?v=4Dc_bri9mjs , Disclaimer - I did not create this tutorial.

Edit: Explained what the code does, and added a disclaimer.

Answer this question