generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

A simple onTouch event binded to a brick not working?

Previous Thread :: Next Thread 
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
29 Apr 2017 08:27 AM
It's kind of what the title implies, but I haven't included the fact that when the brick would be touched, the CameraMode of the player would lock into first person. I've tried multiple methods to work around it, but none have prevailed. My latest script which I devised is shown below, and is simply placed within a transparent brick:

game.Players.LocalPlayer.onTouch(function(player)
player.CameraMode = Enum.CameraMode.LockFirstPerson
end)


- VIShark15
Report Abuse
BlupoV2 is online. BlupoV2
Joined: 12 Nov 2012
Total Posts: 543
29 Apr 2017 08:43 AM
> game.Players.LocalPlayer

You're trying to connect the Touched event to the brick, not the Player (also, Players don't have a Touched event). Since you said the script is parented to the brick, you should change it to script.Parent.

> onTouch

http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched
http://wiki.roblox.com/index.php?title=RBXScriptSignal#Connect

It's Touched. Also, you have to connect the event so it would be Touched:Connect().

(If you want to be technical, calling Touched returns a RBXScriptSignal, or Event, and calling Connect on the RBXScriptSignal runs whatever function you pass to it.)

> function(player)

The Touched event fires with a BasePart, not a Player. To get the player, you would need to use game.Players:GetPlayerFromCharacter() on the BasePart's parent.

http://wiki.roblox.com/index.php?title=API:Class/Players/GetPlayerFromCharacter

script.Parent.Touched:Connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
end)

(You should also check to see if the player actually exists.)

script.Parent.Touched:Connect(function(part)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then
-- Code
end
end)
Report Abuse
BlupoV2 is online. BlupoV2
Joined: 12 Nov 2012
Total Posts: 543
29 Apr 2017 08:46 AM
"calling Touched"

I meant "indexing Touched".
Report Abuse
Plutoeros is not online. Plutoeros
Joined: 13 Feb 2016
Total Posts: 214
29 Apr 2017 09:28 AM
Thanks a lot, got it to work, maybe I should look at the wiki more .-.


- VIShark15
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image