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

Why does my script stop working after one player uses it?

Asked by 4 years ago

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)
0
You shouldn't really be using lighting for storage, other services (serverstorage) exist for that reason turtle2004 167 — 4y
0
ok Sadwowow21 57 — 4y
0
that doesn't help with what I am asking tho Sadwowow21 57 — 4y
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. killerbrenden 1537 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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!

0
there are no errors it just won't give the item to the players backpack Sadwowow21 57 — 4y
0
nvm I accidentally put it into server storage Sadwowow21 57 — 4y
0
Feel free to accept this as an answer :) killerbrenden 1537 — 4y
Ad

Answer this question