Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my script not run multiple times? Crafting GUI

Asked by
Fako16 13
5 years ago
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

Log in to vote
0
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
Thank you! It worked! Fako16 13 — 5y
Ad

Answer this question