I wanted to make a script with a sensor for when a player activates it, it will activate something… I know most things about scripting, but not how to use player scripts… I tried to do this, but I cannot figure out how to make a player script…
I need to know how to make a player script:
local player =
I cannot figure out how to make a script like this…
It depends on how you want the sensor to work. Is it something you touch, something you click on, a gui? Each of those has a different way of leading them into the player so you’d need different code to react to it.
You can get the player from a few things. You can get it from game.Players.LocalPlayer, but only works on the client/local scripts. You can also get the player as arguments from, eg. remote events.
It was script.Parent.LocalPlayer and it was in PlayerScripts
I don’t know how to use it in stuff like sensors to open doors or like a roll call sensor…
If you are talking about ReplicatedStorage events, I do not know how to use those, but I sometimes do it the harder way by not using them, and using BoolValues and IntValues and all other values.
If player scripts require events, then that’s part of why I don’t know how to use it…
Events are not just what you think they are. Your thinking of RemoteEvents which are used for client/server communication for filtering enabled. I am talking generally about events. Eg. mousebutton1click, mouse.Move, ClickDetector.MouseClick
This thread is way too vague. A specific use case would be appreciated. What are you trying to do? There are several different definitions, implementations and use cases for “player activated” code. It can be for a model, for a tool, for a Gui, anything. Details are required.
Also, this:
This is not player-activated code. It’s a form of whitelisting to make something happen. Code is ran automatically in scripts, so the proper term for player-activated code would be event-based code.
Ok, I know how to use those events, but I want a player if block hit, then activate script, like if a block was hit by a player, it would activate something…
Please read up on these kinds of things via the DevForum, Developer Hub or by searching up models that do this. It could help you in the long run. Remember that this category is not for requesting code.
It’s the same event. You would check what player touched the part with an if stament or if you want multiple people, you could even loop in a table. If the player who touched it, is the right player then do what you want.
Again, please read the documentation of the page I provided you. It describes how you can create an event to make something happen when a player touches it. Using the argument that’s also passed to the function, you can use GetPlayerFromCharacter to try and discover which player the part belongs to, then do checking based on the return value if it’s non-nil (e.g. UserId).