Need help with tool giving seat

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want it to wait 5 seconds while player is sitting in a seat and the overhead gui to do some epik tweening after that give da player a tool

  2. What is the issue? Include screenshots / videos if possible!
    The script just freezes without any errors after the 5 seconds has passed

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I haven’t found any solutions online :c

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local seat = script.Parent
local Tween = game:GetService("TweenService")
local ss = game:GetService("ServerStorage")
local toolFolder = ss:WaitForChild("Tools", 5)
local tool = toolFolder:WaitForChild(seat.Name, 5)
local frame2:Frame = script.Parent:WaitForChild("Gui"):WaitForChild("Frame1"):WaitForChild("Frame2")
local frame1:Frame = script.Parent:WaitForChild("Gui"):WaitForChild("Frame1")
local yes = 5
local waitTime = 5

local function lol(plr:Player)
	if not plr:FindFirstChild(tool.Name) then
		tool:Clone().Parent = plr:WaitForChild("Backpack")
		task.wait(.1)
		plr.Character:WaitForChild("Humanoid").Jump = true
	else
		task.wait(.1)
		plr.Character:WaitForChild("Humanoid").Jump = true
	end
end

-- Function to track sitting duration
local function yay()
	local occupant = seat.Occupant
	if occupant then
		local humanoid = occupant.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local plr = game.Players:GetPlayerFromCharacter(humanoid.Parent)
			if plr then
				yes = 5
				frame1.UIStroke.Enabled = true
				frame2.BackgroundTransparency = 0
				task.spawn(function()
					while yes > 0 do
						task.wait(.1)
						if seat.Occupant == humanoid then
							yes = yes - .1
							local size = math.clamp(yes / waitTime, 0 ,1)
							anim = Tween:Create(frame2, TweenInfo.new(.1) ,{Size = UDim2.new(size, 0, 1, 0)})
							-- i aint changing this variable above to a local for a reason
							anim:Play()
							if yes == 0 then
								lol(plr)
								anim:Cancel()
								frame1.UIStroke.Enabled = false
								frame2.BackgroundTransparency = 1
								frame2.Size = UDim2.new(1, 0, 1, 0)
								break
							end
						else
							anim:Cancel()
							frame1.UIStroke.Enabled = false
							frame2.BackgroundTransparency = 1
							frame2.Size = UDim2.new(1, 0, 1, 0)
							break
						end
					end
				end)
			end
		end
	end
end

-- Connect to the Occupant property change
seat:GetPropertyChangedSignal("Occupant"):Connect(yay)

-- In case a player is already sitting when the script starts
if seat.Occupant then
	yay()
end

image

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

idk if thats the problem but you’re not calling lol(plr) in the else bracket

i can’t find it

abcdefghijk(30)

nvm i read it wrong

3030303030

still broken though

30 30 30 30 30

local TS = game:GetService("TweenService")
local Seat = script.Parent
local SS = game:GetService("ServerStorage")
local toolFolder = SS:WaitForChild("Tools")

local frame2:Frame = script.Parent:WaitForChild("Gui"):WaitForChild("Frame1"):WaitForChild("Frame2")
local frame1:Frame = script.Parent:WaitForChild("Gui"):WaitForChild("Frame1")

local WaitTime = 5

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()	
	
	if Seat.Occupant ~= nil then
		
		local humanoid = Seat.Occupant.Parent:FindFirstChildOfClass("Humanoid")
		local End = false
		
		if humanoid then
			
			local Character = humanoid.Parent
			local Player = game.Players:GetPlayerFromCharacter(Character)
			
			local CurrentTool = toolFolder:FindFirstChild(Seat.Name)
			
			local function Quit(hum)
				spawn(function()
					repeat task.wait()
						hum.Jump = true
					until Seat.Occupant ~= nil
				end)
			end
			
			if Player.Backpack:FindFirstChild(CurrentTool.Name) then
				
				Quit(humanoid)
				
				print("Player have tool")
				
			else
				
				local function _GiveItem()

					local CurrentTool = toolFolder:FindFirstChild(Seat.Name)
					if CurrentTool and Player.Backpack:FindFirstChild(CurrentTool.Name) == nil then

						local CloneTool = CurrentTool:Clone()
						CloneTool.Parent = Player.Backpack
						
						Quit(humanoid)

					else
						Quit(humanoid)
						warn("Tool name: "..CurrentTool.." Doenst finded! ") 
					end

				end

				local function _Start()

					for i = 1,WaitTime do
						if Seat.Occupant == nil or End == true then break end
						wait(1)
						print("Time: _"..i)
						
						-- here u can make animation for u SurfaceGui!
				

					end

					if Seat.Occupant ~= nil then
						_GiveItem()
					end

				end

				local function _Checker()
					spawn(function()
						repeat task.wait()
							if Seat.Occupant == nil then
								End = true
							end
						until End == true or humanoid == nil
						print("Ended!")
					end)
				end

				_Start()
				_Checker()

			end
				
		end
		
	end
	
end)

try this, but i dont make animation for u surface gui

1 Like

thanks for da code :smiley:

30 letters

no problem, make your scripts simpler and clearer :slight_smile:
like the one I wrote.
it will not only simplify your scripting, but also optimize your game.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.