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

Studio does not recognize Gui inside playergui?

Asked by 5 years ago
Edited 5 years ago

https://gyazo.com/b95269dc8d883b2c1bea4f9faea45061 ^ Screenshot I RemoteEvent location

Screenshot | Script locations: http://prntscr.com/jr702s

Code new: in starterplayerscripts: script name "Cash_Adder" | Localscript as seen in screenshot

game.ReplicatedStorage.Cash.OnClientEvent:connect(function(player)
    print(player.Name.."Recieved cash onserverevent..")
    wait(3)
while true do
    player.PlayerGui.Cash.amt.Text = player.leaderstats["Drachma"].Value
wait(10)
if player:GetRankInGroup(4101121) >= 1 then
    player.leaderstats["Drachma"].Value = player.leaderstats["Drachma"].Value + 100
    player.PlayerGui.Cash.amt.Text = "Drachma"..player.leaderstats["Drachma"].Value
end
if player:GetRankInGroup(4101121) == 0 then
player.leaderstats["Drachma"].Value = player.leaderstats["Drachma"].Value + 10
player.PlayerGui.Cash.amt.Text = "Drachma"..player.leaderstats["Drachma"].Value
end
end

end)

Code that fires the script above; Located in StarterGui, Named CashFE, Server Script(Normal)

RE = game.ReplicatedStorage.Cash
RE:FireServer()

Location of RemoteEvent is at the top of this post.

0
ok someone help please Ind1v1duals 43 — 5y
0
So you make an infinate loop each time the Cash remote event is fired? User#5423 17 — 5y
0
It would only be fired once for each player since it fires when they join. Ind1v1duals 43 — 5y

1 answer

Log in to vote
0
Answered by
Async_io 908 Moderation Voter
5 years ago
Edited 5 years ago

Hi there!

I know we talked in the chat a bit, but I don't really think you understand what local scripts and server scripts can do in filtering enabled.

Your original issue was that the server was not able to see the items in PlayerGui. With Filtering-enabled, scripts don't really look too much into the player, so they don't see the different GUIs they have, weapons they have, etc. I recommended that you make your script a local script and have it fire the local script. I failed to tell you that you should really only put the GUI-Editing parts into the local script as local scripts can't really change values all that well. Any value a local-script changes is only seen on the client side, so it's not even noticed by the server.

I'll delve more into this, explain what went wrong, and then help you compose a new script.

LocalScripts vs ServerScripts with FilteringEnabled

I'm sure you may already know this, but it never hurts to recap right? A LocalScript is a script specifically designed for the client-side ( player's computer/ player's P-O-V). A server script is specifically designed for the server-side (what's actually going on in-game/game's P-O-V). Anything you do with a LocalScript is going to be seen by the player and only by the player. Anything you do with a ServerScript is going to be seen by all the players. For instance, with a LocalScript, you could change a Frame's position. This is only seen by the one player. With a ServerScript, you could change the player's health. This is going to be seen by all of the players. With a LocalScript, sometimes you'll run into issues where you need a change to be seen by all players. That's why we have RemoteEvents. Now I don't know a bunch about RemoteFunctions, BindableEvents, and BindableFunctions. Anything remote is considered talking between the client-side and server-side. Anything bindable (I'm pretty confident on this but double check) is talking between either the client-side to client-side or server-side to server-side.

What went wrong

With serverside, they're not all to concern about what's happening for every player. So they're not going to see anything stored into the player's PlayerGui or Backpack. They're only really acknowledging those in case they are supposed to insert something into them. That's more than likely why your ServerScript is having issues changing your GUI around. (It's also important to note that it's not really a ServerScripts job to change GUIs. I'd leave that to the LocalScripts.) I also noticed that you're trying to change a leaderstat's value with a LocalScript, which I blindly suggested. Jumping back to my LocalScripts vs ServerScripts, only the player is going to see your money change. The server isn't going to see it, nor will the other players. Assuming this wasn't your intention, I would suggest making this part happen in the ServerScript. Also, just to mention; you used the wrong fire event in your server script, you also neglected to tell where to fire. When you're trying to tell the client something, you're going to want to fire the client and specify which client you're trying to fire at, followed by your excess arguments. If you're firing the server, you really just fire the server and put whatever arguments you want.

How to fix

Local Script

local re = game:GetService("ReplicatedStorage"):WaitForChild("Cash")
local loopLength = 10


player.leaderstats["Drachma"].Changed:Connect(function(cash) --fires whenever value changes
    player.PlayerGui.Cash.amt.Text = cash
end)


repeat wait(loopLength)
    re:FireServer(game.Players.LocalPlayer)
until script.Parent == nil

Server Script

local re = game:GetService("ReplicatedStorage"):WaitForChild("Cash")

re.OnServerEvent:connect(function(player)
    local drachma = player:WaitForChild("leaderstats"):WaitForChild("Drachma")
    if player:GetRankInGroup(4101121) >= 1 then
        drachma.Value = drachma.Value + 100
    elseif player:GetRankInGroup(4101121) == 0 thn
        drachma.Value = drachma.Value + 10
    end
end)
0
hey dude why you type player when you didnt define it yet? Ind1v1duals 43 — 5y
Ad

Answer this question