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

Click giver script debugging help?

Okay so I'm trying to make a script to where I can click on the coffee machine and it gives you the coffee.

This is what I have but it is breaking:

local coffee = script.Parent.Parent
local function OnMouseClick(Player)
	coffee = script.Parent.Parent
	p = game.Players:GetPlayerFromCharacter(part.Parent)
	if p == nil then return end
	coffee = game.ServerStorage.Coffee:Clone()
	if p.Backpack:FindFirstChild(coffee.Name) ~= nil then return end
	coffee.Parent = p.Backpack
	print("Enjoy your coffee!")
	
end

script.Parent.MouseClick:connect(OnMouseClick)

This is my output: 13:49:57.548 - Workspace.Giver.ClickDetector.Script:4: attempt to index global 'part' (a nil value) 13:49:57.549 - Stack Begin 13:49:57.550 - Script 'Workspace.Giver.ClickDetector.Script', Line 4 13:49:57.551 - Stack End

The name of the part you click is 'Giver'.

If you could tell me the error I messed up on the script and not how to fully fix it I would appreciate it because I would still like to learn how to fix it myself :).

2 answers

✓ Accepted answer

Thewsomeguy, that would error. The MouseClick event gives the arguement Player as in the game.Players player, so to fix the script he would need to have p = Player, which would make the script work correctly, but in the end this makes p kind of useless so I would just suggest removing p as a variable and substitute all p's for Player, but of course that is just a trivial adjustment.

You defined your Player parameter as Player, but you're calling :GetPlayerFromCharacter using part, which isn't defined. On line 04, change part, to Player (leave the .Parent part, too).

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