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.
Add +1 to the leaderboard when touched a block?
3 answers
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
1 comment
You just spoonfed him, he's not gonna learn anything from it, if you're a true developer, you would know what your scripting, but in this case, he doesn't and you are just doing the work for him, you didn't even explain anything to him, you just told him to add that script and that's it :/
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.
3 comments
jeez burn
Thats just unnessesary, if you dont wanna help new people then just leave. Thats what this site is for. No one appriciates you being a jerk to him.
Thats just unnessesary, if you dont wanna help new people then just leave. Thats what this site is for. No one appriciates you being a jerk to him.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
ScriptingHelpers is not a website for requesting scripts. If you want to learn to script, there are many different websites that you can use, including https://developer.roblox.com
Well first of all you gotta create a leaderboard with IntValue added to the player, named "leaderstats" and add another IntValue within that call it anything, like points for example. When you touch a block just connect a function which uses the paramter within the .Touched:connect(paramter-refering to character) and use the function GetPlayerFromCharacter to find the actual player n edit the val