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

Not enabled script when player doesn't have tool?

Asked by
MattVSNNL 620 Moderation Voter
3 years ago

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!

0
is the whole thing in a server script Gmorcad12345 434 — 3y
0
if it is it'll not work, if I remember correctly MouseButton1Click doesn't fire on a server sided script Gmorcad12345 434 — 3y
0
Omg thank you so much, You saved my time! MattVSNNL 620 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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.

0
It's a server script MattVSNNL 620 — 3y
0
Ohh :D, MouseButtton1Click does not fire on server sided script :D. BeautifulAuraLover 371 — 3y
Ad

Answer this question