Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 5 years ago

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 :/

0
What a legend. oreoollie 649 — 5y
0
You would just run the function attached to the click detector User#5423 17 — 5y
0
This IS possible. You’re literally requesting for the 'events'. User#19524 175 — 5y

1 answer

Log in to vote
2
Answered by
oreoollie 649 Moderation Voter
5 years ago

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!

0
Hah. In line 2, the plr parameter is a Player object, not a string. User#19524 175 — 5y
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. mattscy 3725 — 5y
0
Thankyou NoirPhoenix 148 — 5y
0
I've just prntScreened your answer @Oreo just incase incapaz uses his magical powers to take it down. NoirPhoenix 148 — 5y
View all comments (2 more)
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! :) oreoollie 649 — 5y
0
@NoirPhoenix Incapaz has no magical powers to take down answer. Don't worry. oreoollie 649 — 5y
Ad

Answer this question