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

Raining Player Points help?

Asked by 10 years ago

I've been trying for the last two days to come up with an effective script that will make it rain bricks with PP in them. I've used multiple scripts but they all don't work correctly. What I need is a script inside the brick that when it touches the ground it will disappear in 2 seconds but if someone touches it before that then they will be rewarded with 3 player points, then it will be destroyed. Yes I do have player points in the server.

Most recent failed script:



local PointsService = game:GetService("PointsService") local db = false function onTouched(hit) if (not hit.Parent:FindFirstChild("Humanoid")) or db then return end local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player then if PointsService:GetAwardablePoints() <= 2 then script.Parent:Destroy() end db = true PointsService:AwardPoints(player.userId, 3) wait(2) script.Parent:Destroy() end end script.Parent.Touched:connect(onTouched)
0
Help? Blueguy195 0 — 10y

2 answers

Log in to vote
1
Answered by 10 years ago

On line 3, it says "local db = false", it needs to know what db is. And, what errors did you get, if any.

0
Well, it's a way of using debounce. Debounce can be used by any variable. Shawnyg 4330 — 10y
0
Oh, didn't know that :/ SchonATL 15 — 10y
Ad
Log in to vote
0
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

Well, for this, you'd need 2 sets of scripts. The 1st script I will provide should be named "Hit". That script will award points once somebody touches. The 1st script's parent must be the 2nd script and the 1st script's Disabled property must be set to true. The 2nd script will cause random bricks to fall (You can choose to add in a mesh with a decal or whatever) from the sky across the map. I didn't include this, but you could choose to make a script where after 5 seconds a new Part is introduced to Workspace and it hasn't been removed, it'll delete itself. For this, I recommend changing the name of the 'coins' that'll be falling.

1st script:

local PointsService = game:GetService("PointsService")


function debounce(func)
    local isRunning = false
    return function(...)
        if not isRunning then
            isRunning = true
            func(...)
            isRunning = false
        end
    end
end

script.Parent.Touched:connect(debounce(function(hit)
    if hit.Parent and game.Players:GetPlayerFromCharacter(hit.Parent) then
        p = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not (PointsService:GetAwardablePoints() <= 2) then
            PointsService:AwardPoints(p.userId, 3)
            script.Parent:Destroy()
        end
    end
end))

2nd script:

Intermission = 120 --Amount in seconds of when the next raining coins will occur.
Amount = 20 --Amount of coins you'd like to fall
Hit = script.Hit

-- repeat wait until game.Players.NumPlayers >= 2
--above is if you don't want just 1 person getting everything

wait(5) --This is when the second player joins, I added a wait so it allows their character to initialize.
while true do
    z = 0
    repeat
    a = Instance.new("Part", Workspace)
    --Here, you could add the lines where it would Add meshes to give it a circle shape and maybe add a decal if you want
    --a.BrickColor = BrickColor.ne("Really red")
    --above is if you want it to be a certain color. I picked red since in most games, they're red..
    Hit:clone().Parent = a
    a.Position = Vector3.new(math.random(1,100), math,random(50,100), math.random(1,100)) -- You should change the X and Z axis so it covers your whole Baseplate. You can leave the Y axis alone as it just puts it in the sky.
    z = z+1
    wait(0.8) -- time between the falling of each seperate coin
    until z == Amount
    wait(Intermission)
end

Answer this question