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
