For this i would do, since you were operating from ONLY a local script, hence meaning that the bacpack wouldn't clear on the server side and would cause problems later on:
The edited local script
local player = game.Players.LocalPlayer
local stats = player:WaitForChild("leaderstats")
local remoteEvent = game.ReplicatedStorage:WaitForChild("clearEvent")
while wait() do
local energy = stats:WaitForChild("Energy")
if energy.Value == 250 then
remoteEvent:FireServer()
end
end
And then put a server script wherever you want (preferably serverScriptService) with this code, this will be used to clear the inventory:
local remEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)
remEvent.Name = "clearEvent"
remEvent.OnServerEvent:Connect(function(player)
local stats = player:WaitForChild("leaderstats")
local energy = stats:WaitForChild("Energy")
if player.leaderstats.Energy == 250 then
local gear = player.Backpack:GetChildren()
for i, child in ipairs(gear) do
child:Destroy()
print(child.." Has been removed from "..player.." Inventory")
end
end)
(Note: I edited my question due to admin request, now it's easier to understand.)
5 comments
Can you give me more info on how I can do this? The link wont work.
Can you give me more info on how I can do this? The link wont work.
I edited your script, just copy that, but i rather you learn and understand first instead of just copying
it wont work.
I fixed the link