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

How to make a cookie giver?

Asked by 9 years ago

Im trying to make a script so when you click on the cookie it gives you the cookie in your starter backpack ive tried several times and its failing can anyone help me? ive tried this script with a click

detector dist = 10

function onClicked()
    local p = game.Players:GetChildren()
    for i = 1, #p do
        if (p[i].Name ~= script.Owner.Value) then
            if (p[i].Character.Torso.Position - script.Parent.Position).magnitude < dist then
                game.Lighting.Cookie:clone().Parent = p[i].Backpack 

            end
        end
    end 
end

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

1 answer

Log in to vote
0
Answered by
Ryzox 220 Moderation Voter
9 years ago

Really unsure what you are attempting to do with that script and it's really messy and not in code block so I cannot read it properly and tell you what's wrong, so I'll just make another script for you.

Okay so assuming your layout is like this:

  • Part
    • ClickDetector
    • Script

Then I would suggest doing this:

script.Parent.ClickDetector.MouseClick:connect(function(player)
    game.Lighting.Cookie:clone().Parent = player.Backpack
end)

It's really as simple as that.

0
Man Thanks so much I think i over thaught it but thanks alot simple script worked kennyspy222 0 — 9y
Ad

Answer this question