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

Not enabled script when player doesn't have tool?

I'm making a simulator and for the shop, I had a bug where if you already had the tool you would not get it, But there is a saving tool, So when I rejoin I can buy the item again, I wrote some code and now it doesn't work anymore, Can anyone help me?

Here's my code:

player = script.Parent.Parent.Parent.Parent.Parent.Parent
bucks = player.leaderstats.Bucks
price = 25
tool = game:GetService("ReplicatedStorage"):FindFirstChild("Woods"):FindFirstChild("AmericaWood")
infoFrame = script.Parent.Parent

function buy()
	if bucks.Value >= price then
		if not player:FindFirstChild(tool) then
			script.Disabled = true
		else
			bucks.Value = bucks.Value - price
			local clone = tool:Clone()
			clone.Parent = player.Backpack
			local clone2 = tool:Clone()
			clone2.Parent = player.StarterGear
			player:WaitForChild("Backpack"):FindFirstChild("Wood"):Destroy()
			script.Disabled = true
		end
	end
end


script.Parent.MouseButton1Click:Connect(buy)

If anyone could help, Please help me, Thank you!

3 comments

0

is the whole thing in a server script

0

if it is it'll not work, if I remember correctly MouseButton1Click doesn't fire on a server sided script

0

Omg thank you so much, You saved my time!

1 answer

If I understand it correctly your script should disable it self if player already has the tool. Your conditions are broke.

player = script.Parent.Parent.Parent.Parent.Parent.Parent
bucks = player.leaderstats.Bucks
price = 25
tool = game:GetService("ReplicatedStorage"):FindFirstChild("Woods"):FindFirstChild("AmericaWood").Name
infoFrame = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function(plr)
    if bucks.Value >= price then
        if plr.Character:FindFirstChild(tool) or plr.Backpack:FindFirstChild(tool) then
            script.Disabled = true
        else
            bucks.Value = bucks.Value - price
            local clone = tool:Clone()
            clone.Parent = player.Backpack
            local clone2 = tool:Clone()
            clone2.Parent = player.StarterGear
             if player:WaitForChild("Backpack"):FindFirstChild("Wood") then
                player:WaitForChild("Backpack"):FindFirstChild("Wood"):Destroy()
             end
            script.Disabled = true
        end
    end
end)

I dont understand why you are doing this stuff with disabling the script, and next time please say clearly what is not working, which error is popping up and what do you want us the script to do. I hope I understood you well, and I hope this helped. Have a good day.

2 comments

0

It's a server script

0

Ohh :D, MouseButtton1Click does not fire on server sided script :D.

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