I'm trying to make a backpack/inventory shop similar to the one in Mining Simulator. I'm now trying to script exiting the shop, which I'm doing by firing a remote event. However, upon clicking the exit button, the ScreenGui updates on the server side but not the client side. I am scripting this in a local script located in ServerScriptService. Here's my local script:
exitbuttonevent = game.ReplicatedStorage.ExitButtonClicked cam = workspace.CurrentCamera local function exitbuttonclicked() local inventory = game.Players.LocalPlayer.PlayerGui:WaitForChild("inventory") inventory:WaitForChild("InventoryShopFrame").Visible = false inventory:WaitForChild("Storage"):WaitForChild("OpenInventory").Parent = inventory inventory:WaitForChild("Storage"):WaitForChild("inventorylabel").Parent = inventory inventory:WaitForChild("Storage"):WaitForChild("Shop").Parent = inventory cam.CameraType = Enum.CameraType.Custom cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid end exitbuttonevent.OnServerEvent:Connect(exitbuttonclicked)
Can I have some help on this? Also, please ignore the camera stuff, if that doesn't work I'll test it later. I'm more worried about the GUI. Thank you!
You're confused with alot of stuff here. This is not an answer but it will help you understand more about RemoteEvents
ServerScriptService is self explanatory it's just for Scripts or ModuleScripts.
exitbuttonevent.OnServerEvent:Connect(exitbuttonclicked)
I don't understand because you never fired a RemoteEvent. There are some examples at the bottom of the page.
When a player wants to open the shop, do it on the client. When the player wants to purchase somthing do on a serverscript using a remote event.
Example:
LocalScript
TextButton.MouseButton1Click:Connect(function() -- when a player clicks a button on the client remoteEvent:FireServer(PriceOfTool) -- sends a signal to the server with an argument priceOfTool end)
ServerScript
remoteEvent.OnServerEvent:Connect(function(client, PriceOfTool) --[[ we have the PriceOfTool parameter since we sent the price to the server. The client parameter is by default whenever OnSeverEvent is fired we get the player that fired it.]] local leaderstats = client.leaderstats if leaderstats.Cash.Value >= PriceOfTool then Tool:Clone().Parent = client.Backpack leaderstats.Cash.Value = leaderstats.Cash.Value - PriceOfTool end end)
Anymore questions? Just reply below.
exitbuttonevent = game.ReplicatedStorage.ExitButtonClicked cam = workspace.CurrentCamera local function exitbuttonclicked() local inventory = game.Players.LocalPlayer.PlayerGui:WaitForChild("inventory") inventory:WaitForChild("InventoryShopFrame").Visible = false inventory:WaitForChild("Storage"):WaitForChild("OpenInventory").Parent = inventory inventory:WaitForChild("Storage"):WaitForChild("inventorylabel").Parent = inventory inventory:WaitForChild("Storage"):WaitForChild("Shop").Parent = inventory
cam.CameraType = Enum.CameraType.Custom
end dont use onserver event because it on server side!