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

How to make a cookie giver?

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

✓ Accepted answer

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.

1 comment

0

Man Thanks so much I think i over thaught it but thanks alot simple script worked

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