You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want my tool to not work at all when seated in a seat (ie. vehicle seat)
What is the issue?
I do not know how to script this, as I am fairly new to scripting, I can get by here and there, but not enough to figure out this issue
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking for this issue everywhere, all I have found (which I currently implement, see below) is a script that disables the tool when you first sit in the seat, but then the player can still use it after that. I want to disable the tool completely until they are out of the seat again.
Here is my current script, parented to the seat:
local Players = game:GetService(âPlayersâ)
local Seat = script.Parent
Seat:GetPropertyChangedSignal(âOccupantâ):Connect(function()
local humanoid = Seat.Occupant
if not humanoid then return end
humanoid:UnequipTools()
end)
local Player = game:GetService("Players").LocalPlayer
local Tool = script.Parent
local Character = Player.Character
local Seated = false
if not Character or not Character.Parent then
Character = Player.CharacterAdded:Wait()
end
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Seated then
Seated = true
elseif NewState ~= Enum.HumanoidStateType.Seated then
Seated = false
end
end)
-- Tool code here (use Seated variable to determine whether your tool works or not)
You can use that, the variable Seated will be true if they are sat, false if they are not, and you can use that variable to help you decide whether the tool should work or not.
Thatâs because you didnât do what I said. You shouldâve coded the tool within the parameters of Seated == true,
like so
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Tool = script.Parent
local Character = Player.Character
local Seated = false
local Equipped = false
if not Character or not Character.Parent then
Character = Player.CharacterAdded:Wait()
end
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Seated then
Seated = true
elseif NewState ~= Enum.HumanoidStateType.Seated then
Seated = false
end
end)
Tool.Equipped:Connect(function()
Equipped = true
end)
Tool.Unequipped:Connect(function()
Equipped = false
end)
UIS.InputBegan:Connect(function(Input, Processed)
if not Processed and Input.UserInputType == Enum.UserInputType.MouseButton1 and Equipped == true and Seated == false then
print("Player clicked")
end
end)
That will print âPlayer Clickedâ everytime the player clicks WHILE the tool is equipped as long as they are not seated, and not clicking a GUI.
When i put Astralâs script into the tool, I used a regular script⌠however, when I tried my first script in the starter scripts i used a local script.
Follow up question: Does everything remain the same if the tool doesnt begin in the starterpack? Once someone picks up the Jet Pack tool from the workspace, I will still be calling for it from the playerâs backpack?
I ended up moving the tool to the workspace and putting a local script in it like this:
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Tool = script.Parent
local Character = Player.Character or Player.CharacterAdded:wait()
local Seated = false
local Equipped = false
local mouse = Player:GetMouse()
if not Character or not Character.Parent then
Character = Player.CharacterAdded:Wait()
end
local Humanoid = Character:WaitForChild('Humanoid')
Humanoid.StateChanged:Connect(function(OldState, NewState)
if NewState == Enum.HumanoidStateType.Seated then
Seated = true
elseif NewState ~= Enum.HumanoidStateType.Seated then
Seated = false
end
end)
Tool.Equipped:Connect(function()
Equipped = true
end)
Tool.Unequipped:Connect(function()
Equipped = false
end)
UIS.InputBegan:Connect(function(Input, Processed)
if not Processed and Input.UserInputType == Enum.UserInputType.MouseButton1 and Equipped == true and Seated == true then
Tool["Jetpack Local"].Disabled = true
end
if not Processed and Input.UserInputType == Enum.UserInputType.MouseButton1 and Equipped == true and Seated == false then
Tool["Jetpack Local"].Disabled = false
end
if not Processed and Input.UserInputType == Enum.UserInputType.Touch and Equipped == true and Seated == true then
Tool["Jetpack Local"].Disabled = true
end
if not Processed and Input.UserInputType == Enum.UserInputType.Touch and Equipped == true and Seated == false then
Tool["Jetpack Local"].Disabled = false
end
end)
Disabling the tool didnât work any which way I tried it, so then i decided to disable the script inside of it instead and that worked. However, I donât know if pointing to the tool directly is the right way, because although it works, sometimes it doesnât work for some players. What do you think of this?