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

Can't clone a model from Replicated Storage?

Asked by
Geko97 29
5 years ago
Edited 5 years ago

I'm trying to clone a model of Replicated Storage to Workspace when the player collides with a part, but when I test it on the Roblox Client, the code not work.

Script inside the part:

local remoto = game.ReplicatedStorage.Torre2
local dinero = "Money"
local Money = script.Parent.Parent.Collect
local boton = game.Workspace.Job1.Boton1

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
    if h then
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if Player and Player.leaderstats[dinero].Value >= 200 then
            Player.leaderstats[dinero].Value = Player.leaderstats[dinero].Value - 200
                remoto:FireServer()
                boton:Destroy()
        end
    end
end)

Script inside Workspace:

game.ReplicatedStorage.Torre1.OnServerEvent:Connect(function()
    local Modelo1 = game.ReplicatedStorage.FreeMachine
    local Clonar = Modelo1:Clone()

    Clonar.Parent = game.Workspace.Job1
    Clonar.Name = "TorreGratis"
end)

game.ReplicatedStorage.Torre2.OnServerEvent:Connect(function()
    local Modelo1 = game.ReplicatedStorage.MachineLV1_J1_P1
    local Clonar = Modelo1:Clone()

    Clonar.Parent = game.Workspace.Job1
    Clonar.Name = "TorreLV1"
end)

I think is a problem using a Remote Event, because when I test it on Roblox Studio, I can clone the model "MachineLV1_J1_P1" but I don't know how to fix it to make it work in the roblox client.

Thanks for read me.

0
but y r u even using a remote. Launderer 343 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

El problema es que intentas usar FireServer en el servidor, cuando solo se puede por el cliente (LocalScript). Los remotos existen para dejar que el servidor pueda comunicarse con el cliente o para que el cliente pueda comunicarse con el servidor. ¿Cómo podría comunicarse con sí mismo? No tiene sentido. El servidor está haciendo todo el trabajo, así que no se necesita remotos porque un cambio hecho por el servidor se replica a todos los jugadores.

local remoto = game.ReplicatedStorage.Torre2
local dinero = "Money"
local Money = script.Parent.Parent.Collect
local boton = game.Workspace.Job1.Boton1

local function Torre1()
    local Modelo1 = game.ReplicatedStorage.FreeMachine
    local Clonar = Modelo1:Clone()
    Clonar.Parent = game.Workspace.Job1
    Clonar.Name = "TorreGratis"
end

local function Torre2()
    local Modelo1 = game.ReplicatedStorage.MachineLV1_J1_P1
    local Clonar = Modelo1:Clone()
    Clonar.Parent = game.Workspace.Job1
    Clonar.Name = "TorreLV1"
end

script.Parent.Touched:Connect(function(hit)
    local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

    if Player and Player.leaderstats[dinero].Value >= 200 then
        Player.leaderstats[dinero].Value = Player.leaderstats[dinero].Value - 200
        Torre2() -- llamando a la funcion "Torre2"
        boton:Destroy()
    end
end)
0
Me siento demasiado estúpido xd. Aun estoy aprendiendo acerca de los Remote Event, guardar datos y muchas cosas más, lo siento por molestar y muchas gracias! Geko97 29 — 5y
Ad

Answer this question