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 stop working after one player uses it?

I have a script that allows you to grab an item by touching it, but when one player clicks it no one else can. Here is my script.

function touch(x)
	local y = x.Backpack
	local z = game.Lighting["[SCP] Card-L2"]
	z:Clone().Parent = y
	script.Disabled = false
	script.Parent.ClickDetector.MaxActivationDistance = 0.5
end

script.Parent.ClickDetector.MouseClick:connect(touch)

4 comments

0

You shouldn't really be using lighting for storage, other services (serverstorage) exist for that reason

0

ok

0

that doesn't help with what I am asking tho

1

He's just giving you a tip on how stuff should be stored for better use. ReplicatedStorage and ServerStorage are better for storing items to be cloned and used.

1 answer

✓ Accepted answer

Some parts of your script doesn't need to be there, and can be manually done in the properties section of the Script and ClickDetector part.

This is what I wrote, and it works perfectly fine.

local debounce = true
local cooldown = 10 --// Change this to the number (seconds) in which they have to wait to click it again

script.Parent.ClickDetector.MouseClick:Connect(function(clicker)
	if clicker ~= nil and debounce == true then
		debounce = false
		local card = game:GetService("ReplicatedStorage"):WaitForChild("[SCP] Card-L2"):Clone()
		card.Parent = clicker.Backpack
		wait(cooldown)
		debounce = true
	end
end)

The only thing you have to change inside the script is the cooldown to how long you want them to wait for them to click it again.

And like turtle2004 said, "You shouldn't really be using lighting for storage, other services (serverstorage) exist for that reason."

ReplicatedStorage and ServerStorage are better for storing items to be cloned and used.

Lighting is for visual effects like blur, sky, etc.

Hope this helped, if it worked then use this as the answer. If it didn't, comment down below what the error is and I'll try to fix it!

3 comments

0

there are no errors it just won't give the item to the players backpack

0

nvm I accidentally put it into server storage

0

Feel free to accept this as an answer :)

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