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.
05 | function onTouched(hit) |
09 | check = hit.Parent:FindFirstChild( "Handle" ) |
13 | local user = game.Players:GetPlayerFromCharacter(hit.Parent) |
14 | local stats = user:findFirstChild( "leaderstats" ) |
17 | local cash = stats:findFirstChild( "XP" ) |
18 | cash.Value = cash.Value + 1000 |
29 | script.Parent.Touched:connect(onTouched) |
Credit to Uberubert
Here's some extra code when left-clicking the basketball:
04 | local vCharacter = Tool.Parent |
05 | local vPlayer = game.Players:playerFromCharacter(vCharacter) |
06 | local spawnPos = vCharacter.PrimaryPart.Position |
07 | spawnPos = spawnPos + (v * 5 ) |
08 | connection:disconnect() |
10 | Tool.BallShadow.Disabled = false |
11 | Tool.Parent = game.Workspace |
12 | Tool.Handle.Position = spawnPos |
13 | Tool.Handle.Velocity = (v * Tool.Power.Value)+Vector 3. new( 0 , 50 , 0 ) |
17 | local character = Tool.Parent; |
18 | local humanoid = character.Humanoid |
19 | if humanoid = = nil then |
20 | print ( "Humanoid not found" ) |
23 | local targetPos = humanoid.TargetPoint |
24 | local lookAt = (targetPos - character.Head.Position).unit |
29 | script.Parent.Activated:wait() |
30 | connection = game:service( "RunService" ).Stepped:connect(onActivated) |
Video: https://www.youtube.com/watch?v=ErSN1PHk4O8
-LukeGabrieI