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

Why does this script not work which uses remote events?

Asked by 2 years ago

Hi i took your script and altered it.

--serverscript

local part = workspace.Part
local remoteEvent = game.ReplicatedStorage.RemoteEvent
local gui = game.StarterGui.ScreenGui.Frame

part.Touched:Connect(function(objectThatTouchedMe)
    if objectThatTouchedMe.Parent:FindFirstChild("Humanoid") then
        local client = game.Players:GetPlayerFromCharacter(objectThatTouchedMe.Parent)
        gui.Visible = false
        remoteEvent:FireClient(client)
    end
end)

--localscript

local remotevent = game.ReplicatedStorage.RemoteEvent
local gui = game.StarterGui.ScreenGui.Frame
local function visiblegui ()
    print("recieved remote call")
end

remotevent.OnClientEvent:Connect(visiblegui)

doesnt work can you tell why?

it prints 'recieved remote call' but the frame doesnt disappear.

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

defining the frame in StarterGui and changing its visibility does nothing. It makes sense that every player has their own GUI so what I mean is that StarterGui is a container that will copy its descendants and parent them to PlayerGui in the PlayerObject.

So instead of this

local GUI = game.StarterGui.ScreenGui.Frame

You want to define the PlayerGui and define the Frame from the PlayerGui

local client = game.Players.LocalPlayer
local GUI = client.PlayerGui.ScreenGui.Frame

Do this in the LocalScript

So if you look in your explorer and start the game

-Players

[Player.Name]

     PlayerGui

         ScreenGui

               Frame
0
Ohh i get it now, thanks! sne_123456 439 — 2y
Ad

Answer this question