Hello there! I am currently working on a Roblox game, but recently ran into an issue. You see, I have one LocalScript under StarterGUI and I want to make it so that if you hit a part, will then disable that script. So to put it simply, is there a way so that when you touch a part that then a LocalScript in StarterGUI stops running? If so, how could I achieve that? Thank you for your time!
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
game.StarterGui.LocalScript.Disabled = true – change local script to whatever your script you want to disable is in startergui.
end
end)
Basically it will set the localscript to disabled, just place this script into the part you want for this to happen
You could just set the script’s disabled property to true.
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
player.PlayerGui.LocalScript.Disabled = true --change to path to the local script.
end
end)
Disabling the script is the only way to force it to stop. If you want to do a snippet of code stopping, you will need to implement a certain function call that tells the code to stop executing similar to event:Disconnect()
or Tween:Stop()
. These can be difficult to implement into existing code.
It successfully disables the code, but the GUI’s that run in the LocalScript don’t disappear, is there a way to fix this?
try
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
game.StarterGui.LocalScript.Disabled = true
yourstartergui:Destroy()
end
end)
–if this works mark me as solution
Could you use a script to find the Gui in the game and then just dsiable the Gui visibility?
There should be a property in the Gui properties to toggle visibility.
Something like this:
script.Parent.Visible = False
This is only for making the Gui invisible not anything else.
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
player.PlayerGui.LocalScript.Disabled = true
player.PlayerGui.LocalScript.Gui.Enabled = false
end
end)
If the gui is parented to the local script this should work.
Otherwise just use Destroy()
on the local script.
been 2 years you alright dude?