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 3 years ago

Hi i took your script and altered it.

01--serverscript
02 
03local part = workspace.Part
04local remoteEvent = game.ReplicatedStorage.RemoteEvent
05local gui = game.StarterGui.ScreenGui.Frame
06 
07part.Touched:Connect(function(objectThatTouchedMe)
08    if objectThatTouchedMe.Parent:FindFirstChild("Humanoid") then
09        local client = game.Players:GetPlayerFromCharacter(objectThatTouchedMe.Parent)
10        gui.Visible = false
11        remoteEvent:FireClient(client)
12    end
13end)
1--localscript
2 
3local remotevent = game.ReplicatedStorage.RemoteEvent
4local gui = game.StarterGui.ScreenGui.Frame
5local function visiblegui ()
6    print("recieved remote call")
7end
8 
9remotevent.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 3 years ago
Edited 3 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

1local GUI = game.StarterGui.ScreenGui.Frame

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

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

Do this in the LocalScript

So if you look in your explorer and start the game

-Players

1[Player.Name]
2 
3     PlayerGui
4 
5         ScreenGui
6 
7               Frame
0
Ohh i get it now, thanks! sne_123456 439 — 3y
Ad

Answer this question