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?
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 :
I am still learning RbxLua.
Thank you for reading.