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

How can i change this script into OnClicked script?

I need help with making this script being OnClicked script, I have tried switching some stuff in the script and it didnt work.

print("Badge Awarder Loaded. BadgeID: " .. script.Parent.BadgeID.Value)




function OnTouch(part)
	if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
		local p = game.Players:GetPlayerFromCharacter(part.Parent)
		if (p ~= nil) then
			print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. p.userId)
			local b = game:GetService("BadgeService")
			b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
		end
	end
end

script.Parent.Touched:connect(OnTouch)

I have tried switching some stuff in the script and it didnt work.

2 comments

0

The only difference is that the MouseClick event passes a 'player' parameter instead of the 'part' parameter, so instead of using GetPlayerFromCharacter you can completely skip that step.

0

So, I can remove it?

1 answer

If you're doing a part that triggers the function if it is pressed down, then it will be like this:

function OnTouch(part)
    -- Codes
end

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

If it was a Gui, then the gui has to be TextButton, or other Gui that is clickable:

function OnTouch(part)
    -- Codes
end

script.Parent.MouseButton1Down:connect(OnTouch)

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