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

How can I get a script to enable a beam on touch?

Asked by 6 years ago

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

Log in to vote
0
Answered by
ziploz 7
6 years ago
script.Parent.Touched:connect(function(plr)
  plr.Character.Humanoid.UpperTorso.BodyFrontAttachment.Beam = true
end)

That will work.

0
Didnt work HeadlessGuide 16 — 6y
0
Error message is: Character is not a valid member of MeshPart HeadlessGuide 16 — 6y
0
Can you tell me what line of your script where the error exists? ziploz 7 — 6y
0
Yes I can tell you, one second please. HeadlessGuide 16 — 6y
0
Line 2 is the error line and the error is 'Character is not a valid member of MeshPart' HeadlessGuide 16 — 6y
Ad

Answer this question