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

EVEN WHEN I TRIED MAKING A SCREEN GUI FILTERING ENABLED COMPATIBLE IT DIDN'T WORK?

Asked by 6 years ago

So lately i have been trying to learn roblox scripting and i have come pretty far (i think) and i have been trying to make a DBZ game in roblox but i am still learning so i wanted to make a filtering enabled compatible screen gui that when clicked opens up another screen gui for the client or player like a shop, when i was scripting i made a RemoteEvent and i duplicated that one and made another one named "GameEvent". Well the reason to make two RemoteEvents was well you will see it later......

Mainly I made 2 RemoteEvents inside of ReplicatedStorage and then i made a screen gui inside of starter gui and inside of the screen gui i put a TextButton naming it "ShopOpen"and a Local Script inside of TextButton. Like this if you didn't understand that = ScreenGui.ShopOpen.LocalScript

And I Put This Inside Of The Local Script:-

script.Parent.MouseClick1Button:Connect(function()
       game.ReplicatedStorage.RemoteEvent:FireServer()
end)

And now i made another ScreenGui naming it "SHOP" this time and inside of that i put a Frame and inside of that i put a TextButton Named "XBUTTON" where it just displays "X" as a font and making it such a size that it looks just like the windows exit button. And now inside of the XBUTTON I Put a Local Script. Like this if you didn't understand that = SHOP.Frame.XBUTTON.LocalScript

And I Put This Inside Of The Local Script:-

script.Parent.MouseClick1Button:Connect(function()
       game.ReplicatedStorage.GameEvent:FireServer()
end)

Then I Dragged "SHOP" Into ServerStorage So I Could Clone() It Into The Player's PlayerGui Folder. And I Made The "XBUTTON" So That I Could Destroy That Made "SHOP" Clone Inside Of The Player's PlayerGui Folder

I Don't Know Why I Made Two RemoteEvents (Maybe To Seperate The Two Scripts From Getting Confused?)

And when i finished That i made two scripts in the ServerScriptService naming the first one "RemoteEventListener" and the other one "GameEventListener".

I Put This Inside Of RemoteEventListener:-

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
       local shop = game:GetService("ServerStorage"):WaitForChild("SHOP")
       local plr = game.Players.LocalPlayer
       shop:Clone().Parent = plr.PlayerGui
end)

And This Inside Of GameEventListener:-

game.ReplicatedStorage.GameEvent.OnServerEvent:Connect(function()
       local plr = game.Players.LocalPlayer
       plr.PlayerGui.SHOP:Destroy()
end)

What This Does Is When The Client Or Player Clicks It On The Client Or Player Screen It Opens A Pop Up Screen Gui Which Shows The Shop. When I Tested It Inside Of Roblox Studio It Worked Just Fine, But When I Played It With The Actual Roblox Player It Didn't Even Show Up!! And I Have Already Tried Using The Method Where The Frame Inside Of The ScreenGui Is On The Clients Screen But It Is Not Visible Only When The Shop Button Is Clicked Visible is turned on and the XBUTTON When Clicked Closes or Makes Visible = false But Yet Again When I Test It Using The Studio Itself It works just fine but when i try to play it with Roblox Player It Gives Out On Me!! Pls Help ------------------------------------------

1 answer

Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
6 years ago

You have a few issues, first I read this line

Then I Dragged "SHOP" Into ServerStorage So I Could Clone() It Into The Player's PlayerGui Folder. And I Made The "XBUTTON" So That I Could Destroy That Made "SHOP" Clone Inside Of The Player's PlayerGui Folder

Please know that a localscript cannot access ServerStorage, and a script cannot access the PlayerGui so I can tell this will probably cause some issues

The second problem I noticed is your remote event receiver

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function()
    local plr = game.Players.LocalPlayer
end)

You cannot access localplayer from a script, luckily for you the first argument of a remote event is the player who sent it, meaning you could do this

local rep = game:GetService("ReplicatedStorage")

rep.RemoteEvent.OnServerEvent:Connect(function(plr)
    print(plr.Name)
end)

What I would do instead for all of this is use a remote function, you can have the client request and receive a GUI from the server using this

-- Localscript:
local func = game:GetService("ReplicatedStorage").RemoteFunction
local player = game:GetService("Players").LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
    local gui = func:InvokeServer()
    warn(gui.Name.." has been received")
end)


-- Script
local gui = game:GetService("ServerStorage").ScreenGui
local func = game:GetService("ReplicatedStorage").RemoteFunction

func.OnServerInvoke = function()
    return gui
end
Ad

Answer this question