Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Tool/Handle Gives Points Rather Than Humanoid?

Hello fellow ROBLOXian Scripters. I am in need of help, I am making a game that implements a Leaderboard consisting two things: XP and Levels. I was wondering instead of me touching the brick, is there a way a tool can touch it and give XP? It's for a basketball game.

--Basically checks if the toucher of the button is a player, then adds money to that player.

local ting = 0 --debouncer

function onTouched(hit)

	if ting == 0 then --debounce check
	ting = 1 --activate debounce
	check = hit.Parent:FindFirstChild("Handle") --Find the human that touched the button

	if check ~= nil then --If a human is found, then

		local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human
		local stats = user:findFirstChild("leaderstats") --Find moneyholder

		if stats ~= nil then --If moneyholder exists then
			local cash = stats:findFirstChild("XP") --Money type
			cash.Value  = cash.Value +1000 --increase amount of money by the number displayed here (500)
			wait(3) --wait-time before button works again
		end

	end

	ting = 0 --remove debounce
	end

end

script.Parent.Touched:connect(onTouched)

Credit to Uberubert

Here's some extra code when left-clicking the basketball:

Tool = script.Parent

function fire(v)
	local vCharacter = Tool.Parent
	local vPlayer = game.Players:playerFromCharacter(vCharacter)
	local spawnPos = vCharacter.PrimaryPart.Position
	spawnPos  = spawnPos + (v * 5)
	connection:disconnect()
	wait()
	Tool.BallShadow.Disabled = false
	Tool.Parent = game.Workspace
	Tool.Handle.Position = spawnPos
	Tool.Handle.Velocity = (v * Tool.Power.Value)+Vector3.new(0,50,0)
end

function onActivated()
	local character = Tool.Parent;
	local humanoid = character.Humanoid
	if humanoid == nil then
	print("Humanoid not found")
	return 
	end
	local targetPos = humanoid.TargetPoint
	local lookAt = (targetPos - character.Head.Position).unit
	fire(lookAt)
end

while true do
	script.Parent.Activated:wait()
	connection = game:service("RunService").Stepped:connect(onActivated)
	wait()
end

Video: https://www.youtube.com/watch?v=ErSN1PHk4O8

-LukeGabrieI

1 answer

✓ Accepted answer

Here you go sir made officially by Resplendid 100%

The Brick is:

--Made 100% by Resplendid
--For LukeGabriel
function onTouch(hit)
local look = hit.Parent:findFirstChild("BallHandler").Value
	local found = game.Players:findFirstChild(look)
	local cash = found:findFirstChild("leaderstats")
	cash.XP.Value = cash.XP.Value+1000
	print("Gave +1000 XP")
end
script.Parent.Touched:connect(onTouch)


and the leaderstats in workspace by itself:

--Made 100% by Resplendid
--For LukeGabriel
local playerStats = {} --this keeps a list of the stats for each player that enters the game
 
 game.Players.PlayerAdded:connect(function(player)
     local leaderstats = Instance.new("Model", player)
     leaderstats.Name = "leaderstats"
	 local points = Instance.new("IntValue", leaderstats) -- Lines 10, 11, and 12 are removable. Remove them if you want only the rank to be displayed.
	 points.Name = "XP"	 
     playerStats[player] = leaderstats 
 end)

Also there needs to be a IntValue inside of the ball called "BallHandler" with a script of:

while wait() do
	plr=game.Players:FindFirstChild(script.Parent.Parent.Parent.Name)
	if plr then
		script.Parent.Value=plr.Name
	end
end

Here you go! It worked for me and it should work for you. Also, give me credit for this work.

Thanks, Resplendid.

This discussion is preserved as it was. New answers, comments, and votes are closed.