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)
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.