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

Is it possible to get NPCs to interact with part click detectors?

Hello. I'm working on my game and want my NPCs to assist the player if there is not a sufficient amount of players. This will require for input interaction between a NPC and part. I was just wondering if such a thing was possible and what events would be required if it is possible. BTW: THIS IS NOT A REQUEST @incapaz :/

3 comments

0

What a legend.

0

You would just run the function attached to the click detector

0

This IS possible. You’re literally requesting for the 'events'.

1 answer

✓ Accepted answer

No, not directly. It is possible to emulate the ClickDetector being clicked using BindableEvents. I would just add a listener for the bindable event in the script with the click detector. Then when the NPC "decides" to help the player, it could fire the event with the player argument as NPC or something. Example code below.

Part Script:

function PartClicked(plr)
	if plr == "NPC" then -- Optional if you want to change what happens when a bot clicks it
		--Do stuff
	else --Real player clicked it
		--Do stuff
	end
end

event.OnEvent:Connect(PartClicked)
clickDetector.MouseClick:Connect(PartClicked)

NPC Script:

function HelpPlayer()
	event:Fire("NPC")
end

I hope my answer helped you, if it solved your problem, please remember to mark it as correct!

6 comments

0

Hah. In line 2, the plr parameter is a Player object, not a string.

0

No, it is a string when he fires the BindableEvent for the NPC, and an object if a player clicks. Because he is just using an else, and since players are not a string, it will work perfectly fine.

0

Thankyou

0

I've just prntScreened your answer @Oreo just incase incapaz uses his magical powers to take it down.

0

@incapaz Actually, no it's not. If you actually read my code then you would see that I fire it with the string "NPC". Please remember to read code before critquing it! :)

0

@NoirPhoenix Incapaz has no magical powers to take down answer. Don't worry.

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