Function doesn't work for some reason

Hey guys, I’m a starter scripter and I need some help with this, I don’t know what’s going on, but the function isn’t working at all for some reason. It doesn’t respond to print scripts and such. There are no errors at all but the function isn’t working. Any clue on what’s going on?

local Gui = script.Parent
local reloadTime = 24.5
local Handle = Gui.Parent.Handle
local microwaveSound = Handle.MicrowaveSound
local InteractButton = Gui.InteractButton


local Debounce = false

InteractButton.MouseButton1Click:Connect(function()
	print("it works")
	if Debounce == false then
		Debounce = true
		microwaveSound:Play()
		wait(reloadTime)
		Debounce = false
	end
end)

image

3 Likes

local script only works on player, do it in server script
edit: no, its actually in player

1 Like

It needs to be a localscript not a regular script.

I’m pretty sure I wrote it in the server script? Hold on I’ll boot up Roblox Studio again because my PC randomly shut down

oh, this is tool… then yes, try to do it on local script

You should check

  • Where the tool is placed
  • If the InteractGUI really is visible
  • Try changing to a localScript

Normal scripts also work with UI so that shouldn’t be a problem, the script is probably not running at all because of the tool’s parent (?)

I put it on a localscript but it still doesn’t work, also the InteractGUI is visible on my screen, and the tool parent is Workspace (until it gets picked up)

Are you sure the script is running at all?

1 Like

LocalScripts don’t run in tools.

Also I’m basically ripping off blocks of scripts from a Roblox gear

and the gear works but mine doesn’t, also the megaphone gear sound script is not in localscript, it is in a normal script

They do if they are parented to StarterPack for example

1 Like

mmm… This is weird. try to do this:

local Gui = script.Parent
local reloadTime = 24
local Handle = Gui.Parent.:WaitForChild("Handle")
local microwaveSound = Handle:WaitForChild("MicrowaveSound")
local InteractButton = Gui:WaitForChild("InteractButton")

print("loaded")
1 Like

It’s giving me an error

1 Like

whAt… show full code with screenshot

local Gui = script.Parent

local reloadTime = 24

local Handle = Gui.Parent:WaitForChild(“Handle”)

local microwaveSound = Handle:WaitForChild(“MicrowaveSound”)

local InteractButton = Gui:WaitForChild(“InteractButton”)

print("loaded")

local Debounce = false

InteractButton.MouseButton1Click:Connect(function()

print("it works")

if Debounce == false then

Debounce = true

microwaveSound:Play()

wait(reloadTime)

Debounce = false

end

end)


Edit: The script I copy and pasted up there seems to have glitched, I don’t know what caused it or how to fix it

1 Like

I just checked, localScripts inside tools run only when you pick them up, but screenGuis don’t get enabled when you pick it up. Are you sure you are testing with the right button?

wrong character, not the double ’ but "
or you can use single ’
image

The ScreenGui appears on my screen when I pick up the tool though
Edit: Oh sorry didn’t really understand your message, I’m currently using a normal script right now, so the ScreenGui pops up.

Oh okay, I’ll try out the script now.

It prints out “loaded” but doesn’t print the print command in the function command.