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 get a script to enable a beam on touch?

So I have a part in my game with a script in, the script says this:

function onTouch()
	while true do
		StarterPlayer.StarterCharacter.UpperTorso.BodyFrontAttachment.Beam = true
	end
end
script.Parent.Touched:connect(onTouch)

Im not sure whats wrong with the script, I myself being completely new to scripting have no idea myself so can I get some help here please?

The basic idea is that when the player touches the part (there is already an attachment and beam connected to the part the beam is going to) the script registers the part being touched and goes to the starterplayer where my custom avatar is sitting (it works being a custom avatar too) and it goes into the character and the uppertorso andthen finds the attachment that has the beam in it (I put all this in the script above) at the moment the beam is disabled (enabled button but not checked) and the script needs to enable it when the player steps on it. When the player steps off of the part I also want the beam to be disabled again (however I had a thought on turning the beam on I have no clue of turning it off seeing as what I think for turning it off doesnt work) I have no clue where it is going wrong. Please help me as soon as you can :)

1 answer

script.Parent.Touched:connect(function(plr)
  plr.Character.Humanoid.UpperTorso.BodyFrontAttachment.Beam = true
end)

That will work.

5 comments

0

Didnt work

0

Error message is: Character is not a valid member of MeshPart

0

Can you tell me what line of your script where the error exists?

0

Yes I can tell you, one second please.

0

Line 2 is the error line and the error is 'Character is not a valid member of MeshPart'

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