I'm trying to make a script that when you touch a certain block, it adds 1 (falls) to the leaderboard. I have no idea how to script it so pls i need help.
Hi! This is very simple! Just do the following:
Make a script under the block you want touched and put this in it
script.Parent.Touched:Connect(function(obj) if not obj.Parent:FindFirstChild("Humanoid") then return end game.Players:GetPlayerFromCharacter(obj.Parent).leaderstats.falls.Value = game.Players:GetPlayerFromCharacter(obj.Parent).leaderstats.falls.Value + 1 end)
Short and sweet. With any further questions, feel free to reply to my post. Happy scripting! ~mc3334
debounce = true -- make the part's function active when touched function touched(hit) -- change "touched" to anything you want to be organized, "hit" can also be "part" or "player" whatever you want - it will be use in the function script as the player's Character body part that touched the part if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then debounce = false -- make the function not fire multiple times. If you don't turn debounce to false once the Character touches it, then it will give value to the leaderboard multiple times instead of only one value per touch. local player = game.Players:GetPlayerFromCharacter(hit.Parent) -- find the Player from its Character that touched the part local falls = player.leaderstats.falls --tell where the "falls" is located in the game if you already put it inside the leaderstats/leaderboard script or a ClassName-"NumberValue" with name "falls" as a child of your leaderboard script falls.Value = falls.Value + 1 -- 1 being the number being added to the falls value or change it to whatever number you want to add to its value wait(2) -- how long in seconds the part can be touch again to give away falls/points debounce = true -- make the part's function to be able to give away falls/points again end -- closing of the scripting "if,then" end -- closing of the scripting "function touched(hit)" script.Parent.Touched:Connect(touched) -- connect the "function touched" to the part being touched. The capitalized "Touched" here is how it is supposed to be spelled as it is the event in Roblox's scripting. Lowercase "touched" is from the name you give it in your "function touched(hit)". If you name it "function ontouch(hit)", then in this line, you should type it as script.Parent.Touched:Connect(ontouch) instead.
Maybe learn to script and this is scripting helpers, not script makers.It really explains ur -2 reputation.