Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Speed Badge on Touch Possible?

Asked by 9 years ago

Hey guys,

First of all, I know that this is not an ask and give service, but I would like help on this script.

Basically, if a player reaches a certain speed when they touch a brick, they are awarded a gamepass.

Also, I would like the speed when they touch to be updated on the leaderboard.

This is how I think it would look like:

-- This code is merely an **EXAMPLE**

local plr = game.Players.LocalPlayer

script.Parent.Touched:connect(function(Touched)
    if game.Players:FindFirstChild(Touched.Parent.Name) ~= nil then
        local speed= stats:findFirstChild("Speed Score")
        speed.Value  = plr.Character.Torso.Velocity.magnitude / 1.45

function OnTouch(part)
    if speed.Value < 252
    local b = game:GetService("BadgeService")
    b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
end

script.Parent.Touched:connect(OnTouch)

I have no idea whats going on with this script ATM, so I am hoping that someone here can give me a hand.

Thanks,

  • Michael

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

This is close to what you want.

Your syntax has problems. Remember:

  • if requires a then after the condition
  • if .. then requires an end after the body of the if
  • You should tab each block inward once

You probably just want to check their speed when they touch the part, instead of using two events.

function OnTouch(part)
    local speed = part.Velocity.magnitude
    local character = part.Parent
    if not character then
        return -- A bullet that doesnt have a parent
    end
    local player = game.Players:GetPlayerFromCharacter(character)
    if player then
        -- It is a player that is touching this
        if speed > 100 then
            local b = game:GetService("BadgeService")
            b:AwardBadge(player.userId, script.Parent.BadgeID.Value)
        end
    end
end
script.Parent.Touched:connect(OnTouch)

That should work as long as the object can be passed-through (.CanCollide is false). It will be less consistent otherwise because their physics could arrest their velocity immediately before processing the touched event.

0
Thanks man, you have answered somthing that I have been needing for a LONG time. *Virtual Hugs* Michael007800 144 — 9y
Ad

Answer this question