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

Game Won't Remove Tool After Player Jumps and Touches Ground?

Basically, I have a game where you have a tool, and moving with the tool is okay, but when you jump, and hit the ground without removing the tool after you touch the ground, the tool will be removed from your backpack, and a message will appear.

If we're talking sports, basically when you have a basketball and you're not allowed to jump with the ball while you are not dribbling it, I'm trying to create a script where you can't do that.

This is in a Local Script.

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local humanoid = player.Character:WaitForChild("Humanoid")
local whatever = game.Workspace

local display = game.Workspace.display
local ServStorage=game:GetService("ServerStorage")

local d = true

while wait() do
	wait(math.random(0,10)/10) --basically how the script calculates a humanoid's jump.	
	if d and player.Character:WaitForChild("Humanoid").Jump and player.Character:FindFirstChild("LBA_Ball") and workspace.quarter.Value ~= "P" 
	and workspace.quarter.Value ~= "H" and workspace.quarter.Value ~= "-" then --during practice and halftime.
		wait(2)
		if player.Character:FindFirstChild("LBA_Ball") then
			d=false
			humanoid.WalkSpeed = 0 --stops them where they at so they won't be able to do anything.
			workspace.Sounds.Whistle:Play()
			wait(0.5)
			workspace.Sounds.Whistle:Play()
			wait(0.5)
			workspace.removal.Value=true --removes the ball from player
			workspace.timer.Disabled=true
			workspace.STimer.Disabled=true --these timer scripts stop the clock
			if player.Team==game.Teams["GS Warriors"] then --1st team
				display.Value="Traveling. Cavaliers Ball."
				wait(2)
				display.Value=""
			elseif player.Team==game.Teams["CLE Cavaliers"] then --2nd team
				display.Value="Traveling. Warriors Ball."
				wait(2)
				display.Value=""
			end
			wait(1)
			workspace.removal.Value=false
			workspace.shotclock.Value=24 --resets the clock/time
			local c=game.Players:GetChildren()
			for i=1, #c do
				if c[i].TeamColor==BrickColor.new("Bright red") then
						c[i].Character:moveTo(workspace.pos1.Position,workspace.pos1)--Position
				elseif c[i].TeamColor==BrickColor.new("Bright blue") then
						c[i].Character:moveTo(workspace.pos2.Position,workspace.pos2) --Position
				end
			end
			wait(2)
			workspace.timer.Disabled=true
			workspace.STimer.Disabled=true
			if player.Character.TeamV.Value == BrickColor.new("Bright blue") then --only way i can recall the player depending on their team color
				wait(1)
				workspace.Sounds.Whistle:Play()
				local ball=ServStorage.LBA_Ball:Clone() --ball cloned after "travel"
				wait()
				ball.Parent=workspace
				ball.Handle.Position=workspace.pos1.Position
				workspace.timer.Disabled=false
				workspace.STimer.Disabled=false
				whatever.BluePress.Transparency = 0.98
				wait(4)
				whatever.BluePress.Transparency = 1
			elseif player.Character.TeamV.Value == BrickColor.new("Bright red") then
				wait(1)
				workspace.Sounds.Whistle:Play()
				local ball=ServStorage.LBA_Ball:Clone()
				wait()
				ball.Parent=workspace
				ball.Handle.Position=workspace.pos2.Position				
				workspace.timer.Disabled=false
				workspace.STimer.Disabled=false
				whatever.RedPress.Transparency = 0.98
				wait(4)
				whatever.RedPress.Transparency = 1
			end
			repeat wait() until not workspace:FindFirstChild("LBA_Ball")
		end
		wait(3)
		deb = true
	end
end

I've researched and looked up FreeFalling. I've had success with this script, but it won't work in ServerSide, and it's very glitchy.

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local humanoid = player.Character:WaitForChild("Humanoid")
local whatever = game.Workspace

local display = game.Workspace.display
local ServStorage=game:GetService("ServerStorage")

local isFalling = false --freefalling
local deb = true --debounce

if game.Workspace.Game.scored.Value==true then
script.Disabled=true
wait()
end

humanoid.FreeFalling:connect(function(falling) --the main usage of the script
isFalling = falling
if game.Workspace.Game.scored.Value==false then
if isFalling and deb and player.Character:FindFirstChild("LBA_Ball") and workspace.quarter.Value ~= "P" 
and workspace.quarter.Value ~= "H" and workspace.quarter.Value ~= "-" then
deb = false
while isFalling do
	wait(2)
	print("Falling")
	humanoid.WalkSpeed = 0
	workspace.Sounds.Whistle:Play()
	wait(0.5)
	workspace.Sounds.Whistle:Play()
	wait(0.5)
	workspace.removal.Value=true
	workspace.timer.Disabled=true
	workspace.STimer.Disabled=true
	humanoid.WalkSpeed = 16
	if player.Team==game.Teams["GS Warriors"] then
		display.Value="Traveling. Cavaliers Ball."
		wait(2)
		display.Value=""
	elseif player.Team==game.Teams["CLE Cavaliers"] then
		display.Value="Traveling. Warriors Ball."
		wait(2)
		display.Value=""
	end
	wait(1)
	workspace.removal.Value=false
	workspace.shotclock.Value=24
	local c=game.Players:GetChildren()
	for i=1, #c do
		if c[i].TeamColor==BrickColor.new("Bright red") then
				c[i].Character:moveTo(workspace.pos1.Position,workspace.pos1)--Position
		elseif c[i].TeamColor==BrickColor.new("Bright blue") then
				c[i].Character:moveTo(workspace.pos2.Position,workspace.pos2) --Position
		end
	end
	wait(2)
	workspace.timer.Disabled=true
	workspace.STimer.Disabled=true
	if player.Character.TeamV.Value == BrickColor.new("Bright blue") then
		wait(1)
		workspace.Sounds.Whistle:Play()
		local ball=ServStorage.LBA_Ball:Clone()
		wait()
		ball.Parent=workspace
		ball.Handle.Position=workspace.pos1.Position
		workspace.timer.Disabled=false
		workspace.STimer.Disabled=false
		whatever.BluePress.Transparency = 0.98
		wait(4)
		whatever.BluePress.Transparency = 1
	elseif player.Character.TeamV.Value == BrickColor.new("Bright red") then
		wait(1)
		workspace.Sounds.Whistle:Play()
		local ball=ServStorage.LBA_Ball:Clone()
		wait()
		ball.Parent=workspace
		ball.Handle.Position=workspace.pos2.Position				
		workspace.timer.Disabled=false
		workspace.STimer.Disabled=false
		whatever.RedPress.Transparency = 0.98
		wait(4)
		whatever.RedPress.Transparency = 1
	end
	repeat wait() until not workspace:FindFirstChild("LBA_Ball")
end
wait(3)
deb = true
end
end
end)

Hopefully all the code you see here helps. In conclusion, I'm trying to have a script where, when one jumps with a basketball and doesn't release it before they touch the ground, the ball will be removed and given to the other team. (Both scripts are Local Scripts.)

-LukeGabrieI

1 answer

✓ Accepted answer

The humanoid has a jump property that you can utilize. There is a much simpler option to what you are attempting to do. First, connect a listener function to the Changed event of the Humanoid. Check if the property is jump. If the jump property is false and the player has the ball, then remove the ball and play whatever sequence you have put in place:

humanoid.Changed:connect(function(propertyName)
	if propertyName == "Jump" and not humanoid.Jump then
		if player.Character:FindFirstChild("LBA_Ball") then
			--remove ball
		end
	end
end)

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