Trying to Disable a script when tool is equipped [SOLVED]

Okay so recently I have been trying to disable a sprint script in StarterGui when you equip a tool. The script Ive been using is this:

local Tool = script.Parent
local Start = game.StarterGui

function onEquippedLocal()
    Start:FindFirstChild("ShiftToSprint").Disabled = true
end
function onUnequippedLocal()
    Start:FindFirstChild("ShiftToSprint").Disabled = false
end

Tool.Equipped:connect(onEquippedLocal)
Tool.Unequipped:connect(onUnequippedLocal)

But for some reason, it does not work. As the sprint script still works after its disabled somehow.

So instead I tried to do another script where it would change the parent of the sprint script to a place where it wouldn’t work when tool is equipped, like workspace.

It changed the parent of the script to workspace, but somehow it still kept working???

Other quite similar posts like this just doesn’t work or doesn’t help me as they use the disable property which for some reason, doesn’t even disable the line of code inside.

I am quite new at scripting. So If there is anybody that could help me, that would be very much appreciated.

1 Like

Just fire a bindableevent, which then connects to a func tht disbales sprinting, quite easy as sprinting = false

local Start = game.StarterGui
Hello! In the above line of code, you are accessing the StarterGui, not the PlayerGui.
When the game starts, everything in the StarterGui will be cloned into PlayerGui located in the player!
To make your code works, try this:
local Start = game.Players.LocalPlayer.PlayerGui
Hope it helps :grin:

1 Like

@2XIth Thanks for the help! I had no idea!
Your help is appreciated. Ill start to use that from now on

1 Like

You should place local scripts which aren’t related to Guis inside the StarterPlayerScripts/StarterCharacterScripts folder.

The sprint script is in StarterGui because it also creates a mobile input gui button.