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

Why is my local script tool giver not working? Theres no Error in the Output

I have built a drinks machine and now I want the players to have a tool added to their inventory when they click a button using a clickdetector. I put this local script in the ClickDetector:

local p = game.Players.LocalPlayer
local debounce = true

script.Parent.MouseClick:Connect(function(p)
	local Backpack = p.Backpack
	local Tool = game.ReplicatedStorage.Equipment.BottleDrinks.Cola1
	local Clone = Tool:Clone()
	Clone.Parent = Backpack
	script.Disabled = true
	wait(10)                                                   
	script.Disabled = false
end)

Thank you very much for your great help ^^

1 comment

0

Use a debounce instead of script.Disabled. script.Disabled is unreliable.

1 answer

✓ Accepted answer

----- Local scripts do not work in the workspace, try using a normal script

-----Do not decide p, it can be gotten from the function That is..

script.Parent.MouseClick:Connect(function(playerwhoclicked)
	---Script
end)

-----You cannot disable a script, then enable it from the same script. the script will stop running once you disable it.

----- Instead Try this:

local debounce = true

script.Parent.MouseClick:Connect(function(playerwhoclicked)
	if debounce == true then
		local Backpack = p.Backpack
		local Tool = game.ReplicatedStorage.Equipment.BottleDrinks.Cola1
		local Clone = Tool:Clone()
		Clone.Parent = Backpack
		debounce = false
		wait(10)
		debounce = true
	end
end)

2 comments

0

First of all, thank you for your help, but when I tried the script I got the following error message: "- Workspace.Shops.DevStore.Parts.DrinksVendingMachine.Parts.Screen.SurfaceGui.Background.Buttons.CokeButton.Part.ClickDetector.Script: 6: attempt to index nil with 'Backpack' "

0

replace player who clicked with p

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