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

Not a valid member of PlayerGui?

Asked by
Geko97 29
5 years ago

I'm trying to show a message when you touch a brick, and the script work when I test it in roblox studio, but in a local server not. I know I should use a "Remote Event" for make the script work, but I don't know how exactly I can do that, I'm new using Remote Events/Remote Functions.

I have this script in a brick:

debounce = false

script.Parent.Touched:connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")
        if h and debounce == false then
            debounce = true
            local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
            Player.PlayerGui.ComprarNegocio.Terreno1.Visible = true
            wait(4)
            debounce = false
    end
end)

When I test it in local server I get this error " ComprarNegocio is not a valid member of PlayerGui "

How can I fix it?

1
The server can not access player's PlayerGui, you will need to use a remote event. valchip 789 — 5y
0
the server can access a players gui ffejyos 10 — 5y
0
Nope it can't. It can only see the PlayerGui folder/container, but it can't do anything with it. Pojoto 329 — 5y
0
I know, but how I can use the remote event for fix my script? Geko97 29 — 5y
View all comments (3 more)
0
I've read it and seen tutorials before asking the question, if I'm asking, it's because I do not know how to do it in my script. Geko97 29 — 5y
0
HOLA GEKO :DD User#19524 175 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

Hola Geko.

Mencionado en los comentarios, el servidor no puede modificar los objetos en PlayerGui. El servidor debe de haber puesto el objeto en PlayerGui para que el servidor pueda verlo. Necesitarás un RemoteEvent. Pon uno en ReplicatedStorage.

-- LocalScript dentro de la gui llamada "ComprarNegocio"
local remoto = game.ReplicatedStorage.RemoteEvent -- el nombre de tu evento 

remoto.OnClientEvent:Connect(function() -- escuchando por FireClient para ejecutar el código 
    script.Parent.Enabled = true -- visible 
end) 

Del servidor:

local debounce = false -- las variables locales!! 
local remoto = game.ReplicatedStorage.RemoteEvent -- el mismo remoto de antes

script.Parent.Touched:Connect(function(hit)
    local h = hit.Parent:FindFirstChild("Humanoid")

    if h and not debounce then -- con el operador "not", no se requiere == false 
        debounce = true
        local Player = game.Players:GetPlayerFromCharacter(hit.Parent)

        if Player then -- quizá no sea un jugador, hay que asegurarnos 
           remoto:FireClient(Player) -- necesitamos el jugador para ejecutar el código a ese jugador
            wait(4)
            debounce = false
        end
    end
end)

Y antes de terminar con mi respuesta, te digo por qué sirvió en Roblox Studio.

En el modo "Play Solo", no existe la separación entre el servidor y el cliente. Es el servidor y cliente al mismo tiempo. Por esta razón, el servidor sí pudo modificar a los objetos en PlayerGui. Pero cuando juegas en un servidor, esta separación sí existe.

Finalmente, :connect() está en desuso, sugiero que cambies a :Connect().

Buena suerte con tus juegos

0
Te amo demasiado. Geko97 29 — 5y
Ad

Answer this question