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

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

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

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)

4 comments

0

doesnt work xd

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.

0

wait how do i make it if you are 75 studs and further?

0

Line 1, you change that two what ever you want it to.

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