How to make a part that gives points each time it bounces

I would want to make a part that each time it bounces off a wall it will give you a point (i use the Basic bounce effect given by roblox from CustomPhysicalProperties set the elasticity to 1)

I have no idea how can i do this + i dont know how to script lol

I tried looking answers in devforum but didnt found any

Please give me some ideas or some script examples or if possible the whole idea
Thanks.

1 Like

Will it be giving only 1 player points or the whole server?

1 Like

The game will be only 1 player per server. Basically you will play alone, and the player gets 1 point each time it bounces the part by grabbing it and throw it

I got some free time. I’ll go through with an idea of where to start and how I would do it. Course theres resources there to help you I’ll leave some documentation references to most of the infomation I’ll be using here.

Touched Event
https://developer.roblox.com/en-us/api-reference/event/BasePart/Touched

FIrst a few things I imagine you’ll be using a tool. What I would do is add a STRINGVALUE inside the tool and name it “player”.
and add a script to it.
image
For the tool that is a “BALL”, you want to set a tool.equipped function inside a script of the tool so we can use script.parent for the tools variable and get the player who equipped the tool easy by using the tools parent.

--/!!/  TOOL SCRIPT
local tool = script.parent
local player = tool.parent

Now we can connect this event to a function

--/!!/  TOOL SCRIPT END RESULT
local tool = script.parent --/!!/  where the tool is

tool.Equipped:Connect(function()
 local player = tool.parent --/!!/  getting the tools equipper
 tool.player.Value = player.Name --/!!/  setting the tools string value called "player" to players.Name
end

Pretty simple thats it for the tool.

Now for the “wall” its alittle more complex than the last.
You can put a script inside the wall and use a wall.Touched event so it fires a function you connect to it.

--/!!/  WALL SCRIPT
	local wall = script.Parent
wall.Touched:Connect(function(hit) --/!!/  "hit" is what touched the part

end)

Next you can define the tools name, which here is "BALL"

--/!!/  WALL SCRIPT
	local wall = script.Parent
wall.Touched:Connect(function(hit) --/!!/  "hit" is what touched the part
	local toolsName = "BALL"

end)

Now we can check if hit is equal to toolsName which is "BALL"

--/!!/  WALL SCRIPT
	local wall = script.Parent
wall.Touched:Connect(function(hit) --/!!/  "hit" is what touched the part
	local toolsName = "BALL"

			if hit.Parent.Name == toolsName then --/!!/  is this equal to what we are looking for?

			end

end)

Now if it is true then we need the player, which just so happens to be in the stringValue we set everytime the tool is equipped inside the tool. So what we can do here is get it with hit.Parent.player.Value

--/!!/  WALL SCRIPT
	local wall = script.Parent

wall.Touched:Connect(function(hit) --/!!/  "hit" is what touched the part
	local toolsName = "BALL"

			if hit.Parent.Name == toolsName then
				local player = hit.Parent.player.Value

			end
		end
end)

Now thats all set we need a place to store points… So insert a Value variable. In this case I put it inside my character so we can get it from the character each time.

--/!!/  WALL SCRIPT END RESULT
	local wall = script.Parent
	local deBounce = false --/!!/  deBounce helps with over firing

wall.Touched:Connect(function(hit)
	local toolsName = "BALL"
		if deBounce == false then 
		deBounce = true 

			if hit.Parent.Name == toolsName then
				local player = hit.Parent.player.Value
				game.Players:WaitForChild(player).Character.points.Value += 1
			end

		wait()
		deBounce = false --/!!/  deBounce
		end
end)

To show I just ended up with a small GUI and a script in the character to update every time the value points changes.

2 Likes

Thanks! It was very helpful but i have a problem. I wanna make the points system so that instead of having a leaderstat individually, everyone shares the same leaderstat (everyone on the server). Example:if someone bounces the part in a wall, everyone shares the point and the leaderstat gets +1 point, instead of the player who bounced the ball gets +1 point and everyone else doesnt get anything. I hope u understood my message and that i was clear about it. Do you have any ideas how could i do something close to this?

Sure, this is what I came up with.
My understanding is when the ball hits ALL players get a point.

Using local Players = game:GetService("Players") we can loop through every player with a simple loop.

				for i, player in pairs(Players:GetPlayers()) do
				print(player)
				end
--/!!/  THIS IS A SERVER SCRIPT 
--/!!/  INSIDE THE WALL
local wall = script.Parent
local deBounce = false 
local Players = game:GetService("Players") --/!!/  Grabbing all current players 
local myValuesName = "Coins" --/!!/  the leaderstats \!value name!/ under the leaderstats folder in players character

wall.Touched:Connect(function(hit) --/!!/  Wall got hit
	local toolsName = "BALL" --/!!/  Whats the tools name we are looking for
		if deBounce == false then 
		deBounce = true 

			if hit.Parent.Name == toolsName then --/!!/  Is what we are looking for we hit

				for i, player in pairs(Players:GetPlayers()) do --/!!/  The player loop
				print(player.Character.leaderstats.myValuesName.Value += 1) --/!!/  adding all those values to that leaderstat
				end

			wait()
			deBounce = false 
		end
	end
end)

I did not test this but should work

1 Like

Also the tool doesn’t even need to have a script in it anymore for this to work. The above would do it all.

1 Like