Like you press the chest and your points go to 0, But when you click on it again they go back to you. Is that possible?
Is it possible to make a chest that stores points onclick?
1 answer
Hello,
I assumed that you want to work with FilteringEnabled by default.
Here is an image to help you organise your stuffs properly :Image1, Image2
Script executed when a player enters(Script) :
--Made by EA™
game.Players.PlayerAdded:Connect(function(player)--An event when a player enters the game.
local leaderstats = Instance.new("Model") --Creating a model.
leaderstats.Name = "leaderstats" --Model's name.
local points = Instance.new("IntValue") --Creating a value storage.
points.Name = "Points" --Value storage's name.
leaderstats.Parent = player --Parented model to player who entered the game.
points.Parent = leaderstats --Parented points to the model.
points.Value = 10000 -- Points default value.
end) -- End of function
Script in Chest (Script):
--Made by EA™
local chest = script.Parent.Parent.Chest -- Your chest Item.
local clicker = script.Parent.ClickDetector -- A clickdetector to detect if chest is being clicked.
local RE = Instance.new("RemoteEvent") -- RemoteEvent1
local RE1 = Instance.new("RemoteEvent") -- RemoteEvent2
local debounce = false -- Variable debounce = false
RE.Name = "PointInitialiser" --RemoteEvent1 is the one that changes points to 0.
RE1.Name = "PointReverter" --RemoteEvent2 is the one that reverts your points.
clicker.MouseClick:Connect(function(c) --Event when chest is clicked(Parameter C is the player that clicked the chest)
RE.Parent = c --RemoteEvent1 Parented to player
RE1.Parent = c -- RemoteEvent2 Parent to player
if debounce == false then -- Checks if debounce is false
RE:FireClient(c, tostring(debounce)) -- 1*
else
RE1:FireClient(c, tostring(debounce)) -- 2*
end -- Ends loop.
RE.OnServerEvent:connect(function(player, argt,arg2t) --3*
if debounce == false then -- Verifies if debounce is false.
print("Changed "..player.Name.." Points to : "..arg2t) -- Prettyprinting.
local points = player.leaderstats:findFirstChild("Points") --Searches for points in player.
points.Value = tonumber(arg2t) --Point = 0
debounce = argt -- Debounce = true
end
end)
RE1.OnServerEvent:Connect(function(player, argf,arg2f)--4*
if debounce == true then --Verifies if debounce is true.
print("Changed "..player.Name.." Points to : "..arg2f) -- Prettyprinting.
local points = player.leaderstats:findFirstChild("Points") -- Searches for points in player.
points.Value = arg2f -- 5*
debounce = argf -- Debounce = false
end --
end)--
end)--> Proper ending of loops and functions.
Script in StarterPlayer > StarterPlayerScripts ( Localscript) :
--Made by EA™
local player = game.Players.LocalPlayer -- Declare player as a variable.
repeat wait() until player:FindFirstChild("PointInitialiser") --Wait for RemoteEvent1
repeat wait() until player:FindFirstChild("PointReverter") -- Wait for RemoteEvent2
local RE = player.PointInitialiser --Variable of RemoteEvent1
local RE1 = player.PointReverter -- Variable of RemoteEvent2
local bpoint = {player.leaderstats.Points.Value} --Table to store the first value of player's points.
RE.OnClientEvent:connect(function(arg) -- Server calls client, arg is parsed on the serverscript.
if arg == "false" then --Checks.
local arg2 = player.leaderstats:findFirstChild("Points")
RE:FireServer(true,"0") -- Fires Server an answer telling that arg1 is true and arg2 is 0.
end
end)
RE1.OnClientEvent:connect(function(arg) -- Server calls client, arg is parsed on the serverscript.
if arg == "true" then --Checks.
RE1:FireServer(false,bpoint[1]) -- Fires Server an answer telling that arg1 is false and arg2 is the previous stored points.
end
end)
Note : *1 -- RE:FireClient(c, tostring(debounce)) -- The Server fires a signal to the specified client(c) to change debounce to false.
*2 -- RE1:FireClient(c, tostring(debounce)) --The Server fires a signal to the specified client(c) to change debounce to true.
3* -- RE.OnServerEvent:connect(function(player, argt,arg2t) -- When the client calls the server, the server parses the argument "player" as the player who called and the other 2 arguments ( argt , arg2t ) are variants ( optional ).
4* -- RE1.OnServerEvent:Connect(function(player, argf,arg2f) -- When the client calls the server, the server parses the argument "player" as the player who called and the other 2 arguments ( argf , arg2f ) are variants ( optional ).
5* -- points.Value = arg2f -- The player's points = the argument sent by the client ( arg2f ).
I am still learning RbxLua.
Thank you for reading.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Oh well
What do you mean by chest? Torso or an item storage chest?
Lets say its just a brick that you click and your points go there then you click again and you get them back