Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not a valid member of PlayerGui?

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?

7 comments

1

The server can not access player's PlayerGui, you will need to use a remote event.

0

the server can access a players gui

0

Nope it can't. It can only see the PlayerGui folder/container, but it can't do anything with it.

0

I know, but how I can use the remote event for fix my script?

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.

0

HOLA GEKO :DD

1 answer

✓ Accepted answer

###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

1 comment

0

Te amo demasiado.

This discussion is preserved as it was. New answers, comments, and votes are closed.