Hello, I have recently tried to make a sell pop-up, which is like what pops up in simulators when ur backpack is full, I have made a script on it, but I have failed. Here is the script:
local serverstorage = game:GetService("ServerStorage") local replicatedstorage = game:GetService("ReplicatedStorage") local capacity = serverstorage.BottleValue local player = game.Players.LocalPlayer local Chemicals = player.leaderstats.Chemicals if Chemicals.Value >= replicatedstorage.BottleValue.Value then wait() replicatedstorage.Sell.Parent = player.PlayerGui end
What im trying to do is that when the chemicals hit 10, a popup says that they need to sell their chemicals, the bottlevalue on line 6 is just the limit. However, it doesnt show the gui, can someone help me?
Use :GetService() to retrieve the Players Service
Use :WaitForChild() to make sure something exists before using or changing it
All items within the ServerStorage (as well as ServerScriptService for that matter) will not be replicated to the Client, so you cannot define the capacity value using a LocalScript directly within your current set-up
You also immediately check the Chemicals value instead of anytime it changes so if it doesn't start out as a number greater than or equal to the capacity, then it will not be added to the player's gui. It will also only move it once so if this was somehow fired again, it would be unable to perform the parenting of a now null object.
Since you are using the ServerStorage to hold your BottleValue value, I would suggest using a RemoteEvent to place the Gui for the player.
local serverstorage = game:GetService("ServerStorage") local replicatedstorage = game:GetService("ReplicatedStorage") local remote = Instance.new("RemoteEvent") remote.Name = "AddSellGui" remote.Parent = replicatedstorage local capacity = serverstorage:WaitForChild("BottleValue") game:GetService("Players").PlayerAdded:Connect(function(player) local Chemicals = player:WaitForChild("leaderstats"):WaitForChild("Chemicals") Chemicals.Changed:Connect(function() if Chemicals.Value >= capacity.Value then remote:FireClient(player) end end) end)
local replicatedstorage = game:GetService("ReplicatedStorage") local remote = replicatedstorage:WaitForChild("AddSellGui") remote.OnClientEvent:Connect(function() local clone = replicatedstorage:WaitForChild("Sell"):Clone() clone.Parent = script.Parent end)
However the easiest way to complete this task would be to simply perform everything in a LocalScript and place the BottleValue into the ReplicatedStorage
local player = game:GetService("Players").LocalPlayer local Chemicals = player:WaitForChild("leaderstats"):WaitForChild("Chemicals") local capacity = game:GetService("ReplicatedStorage"):WaitForChild("BottleValue") Chemicals.Changed:Connect(function() if Chemicals.Value >= capacity.Value then local clone = game:GetService("ReplicatedStorage"):WaitForChild("Sell"):Clone() clone.Parent = script.Parent end end)
And that is it. That is immediately when the script starts running. You should listen for the Instance.Changed
event which will fire when a property changes.
lua
chemicals.Changed:Connect(function(newValue)
--// code here
end);
Where newValue
is the updated Value
of Chemicals
.
The contents of ServerStorage
are inaccessible to clients. So whatever is in there will not replicate to them.