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)
On line 3, it says "local db = false", it needs to know what db is. And, what errors did you get, if any.
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