Script not acting as intended only for some players and not for others

Hi, I have a jet pack tool that I scripted to disable when seated so that players don’t fly away in vehicles etc. when they have the jet pack equipped in a seat.

I have this in a local script in StarterPlayerScripts… although it works in studio and in game for me, on both pc and mobile, I have seen it not working for some players in same game with me who were playing both on pc and mobile. Some it worked for them and others it did not, and they were able to equip the jet pack and fly while seated.

I feel the issue lies both in it being a starterscript, maybe the script belongs in the tool? And the other issue might be how i point to the tool in the last few lines of code, maybe I need to point to the backpack instead? Oh and “Jetpack Local” is the local script inside the tool that I am disabling.

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer 
local Tool = game.Workspace["Jet Pack"]
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)
2 Likes

Why are you disabling the script when item is equipped? If someone equips the item before sitting then script wouldnt be disabled, just disable the script when player sits.

1 Like

The script gets disabled when player sits in seat and equips the tool, both those have to be true. When player leaves seat, script gets enabled and tool returns back to normal function.

Script does not get disabled when item is equipped… only when item is equipped AND the player is seated.

1 Like

Yeah but the problem is that players can equip it before sitting, that wouldnt disable the script then. Also you should not look for the tool in workspace but in backpack and inside the character (when its equipped).

1 Like

Oh i forgot to mention i have another script that disables any equipped tools upon sitting. This script discussed above was meant strictly for the jet pack, and for it to disable while seated.

1 Like

Why even have 2 separate scripts? why not just have localscript inside the tool that would look something like

local UIS = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")

local Tool = script.Parent
local Seated,Equipped = false,false

Tool.Equipped:Connect(function()
	Equipped = true
end)
Tool.Unequipped:Connect(function()
	Equipped = false
end)

Humanoid.Seated:Connect(function(IsSeated)
	Seated = IsSeated
end)

UIS.InputBegan:Connect(function(Input)
	if not Equipped or Seated then return end
	
	if Input.UserInputType == Enum.UserInputType.MouseButton1 or Input.UserInputType == Enum.UserInputType.Touch then
		
		--Make the jetpack fly
		
	end
end)
2 Likes

My other script inside the jet pack has a call to fire a onserver event. So it gives errors to combine into one script… and when I change it to a onclient event it doesn’t work.

However, that being said… the scripts do work for me originally, they just don’t work for some players. Why would that be?