Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make a Point giver When you walk into a block?

Asked by 4 years ago

I want to have it when i go into a bush or a part it gives me money on leader stats and it disappear for a while and comes back, i cant seem to find any code on how to do Any help will help.

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago

Articles I used to learn how to do this: Leaderboards - https://developer.roblox.com/en-us/articles/Leaderboards OnTouched - https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched

bush = game.Workspace.Bush
isHidden = false 

--Give the player a Points leaderboard when they join the game
game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local Points = Instance.new("IntValue")
    Points.Parent = leaderstats
    Points.Name = "Points"
    Points.Value = 0
end)


--Fires a function when the player touches the bush
bush.Touched:Connect(function(hit)
    --if the bush is not hidden and the thing touching the bush is a player...
    if(not isHidden and game.Players:FindFirstChild(hit.Parent.Name))then
        --give the player one point and make the brick hidden again
        local player = game.Players[hit.Parent.Name]

        player.leaderstats.Points.Value = player.leaderstats.Points.Value + 1

        bush.Transparency = 1
        bush.CanCollide = false 
        isHidden = true

        wait(2) -- wait 2 seconds to make the bush visible again after being touched

        isHidden = false 
        bush.CanCollide = true
        bush.Transparency = 0

    end
end)


Ad

Answer this question