Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my script not run multiple times? Crafting GUI

local name = script.Parent.Parent.ItemName
local resources = script.Parent.Parent.Resources


if script.Parent.MouseButton1Down then
	function bow()
		if name.Text == "Bow" then
			print("Bow Given")
		elseif name.Text == "Select a Item" then
			print("Not Enough Materials")
		end
		end 
		bow()
	end

This is my script, I'm just testing out a crafting GUI and when I test the game it immedietaly prints Not Enough Materials and when I click the 'Craft' button (which should run the script again) nothing new prints, even though it should since the name.text is Bow.

Any Help is appreciated.

1 answer

✓ Accepted answer

For first, you created a function in "MouseButton1Down", for this you need to use local function, and your click is incorrect

and use MouseButton1Click. you can see more here: MouseButton1Click - Wiki page

For use functions and click you need to use this:


function print_text(text)
	print(text)
end

script.Parent.MouseButton1Click:Connect(function()
	print_text("Hello")
end)

Here is your fixed script:

local name = script.Parent.Parent.ItemName
local resources = script.Parent.Parent.Resources

function bow()
	if name.Text == "Bow" then
		print("Bow Given")
	elseif name.Text == "Select a Item" then
		print("Not Enough Materials")
	end
end 

script.Parent.MouseButton1Click:Connect(function()
	bow()
end)

Hope it helped :D

Errors? tell-me on comments.

1 comment

0

Thank you! It worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.