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

Why does this not change a Value everytime a player scores with a basketball?

Asked by 5 years ago
Edited 5 years ago

Soo, Basically everytime a player shoots with a basketball and is exactly 75 studs away from the basket/hoop/part then it should add 3 to the value.

local threepointer = 75
local goal = workspace.HoopOne

for i,v in pairs(game.Players:GetChildren()) do
    if v.Character:FindFirstChild("Basketball") then
        ballposition = v.Character.Basketball.Handle.Position
    end
end

goal.Touched:Connect(function(hit)
    if hit.Parent == ("Basketball") then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
            if (ballposition.Position -goal.Position).magnitude <= 75 then
                workspace.one.Value = workspace.one.Value + 3
            end
    end
end)

1 answer

Log in to vote
0
Answered by
xPolarium 1388 Moderation Voter
5 years ago
Edited 5 years ago

You're not comparing the correct data type.

Line 11, you want to compare hit.Parent (Which looks like its the character model) to string "Basketball". Instead do hit.Name.

goal.Touched:Connect(function(hit)
    if hit.Name == "Basketball" then
        local character = hit.Parent
        local hrp = character.HumanoidRootPart


        if (hrp.Position - goal.Position).magnitude >= 75 then
            workspace.one.Value = workspace.one.Value + 3
        end
    end
end)

edit: should be the distance between the player's current pos and the goal's pos

Full script:

local threepointer = 75
local goal = workspace.HoopOne

--Use GetPlayers() to make sure you only get players
for i,v in pairs(game.Players:GetPlayers()) do
    if v.Character:FindFirstChild("Basketball") then
        ballposition = v.Character.Basketball.Handle.Position
    end
end

goal.Touched:Connect(function(hit)
    if hit.Name == "Basketball" then
        local character = hit.Parent
        local hrp = character.HumanoidRootPart


        if (hrp.Position - goal.Position).magnitude >= threepointer then
            workspace.one.Value = workspace.one.Value + 3
        end
    end
end)
0
doesnt work xd WillBe_Stoped 71 — 5y
0
Should be fixed now. You were getting the distance between the ball's pos (Which is probably near the goal) and the goal's position. The initial position should be the character. xPolarium 1388 — 5y
0
wait how do i make it if you are 75 studs and further? WillBe_Stoped 71 — 5y
0
Line 1, you change that two what ever you want it to. xPolarium 1388 — 5y
Ad

Answer this question