|
| 02 Apr 2014 04:47 AM |
How do I make a script that does something when the Player touches a certain object?
Example; When the player touches a specific object/part. A script makes the ScreenGui text to change.
Please make the Script re usable or something. THX! |
|
|
| Report Abuse |
|
|
|
| 02 Apr 2014 04:50 AM |
local part=workspace.Part --Show the script which part will activate the action
local function action(hitBy)--define what happens when 'part' is touched print(tostring(part).." was hit by "..tostring(hitBy).."!") end
part.Touched:connect(action)--Connect the 'action' function to the 'Touched' event |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2014 03:36 AM |
It doesn't work. This is the script you gave me. local part=workspace.Part1 local function action(hitBy)Game.Workspace.StarterGui.Subtitles.Text="Testing Done" print(tostring(part).." was hit by"..tostring(hitBy).."!") end
part.Touched:connect(action) When I touched the brick, the output window printed : "Disconnected event because of exception" And the GUI's text didn't change. |
|
|
| Report Abuse |
|
|
|
| 03 Apr 2014 03:39 AM |
I noticed an error and I edited the script but it still doesn't work! Still says Disconnected event because of exception.
local part=workspace.Part1 local function action(hitBy)Game.Workspace.StarterGui.Subtitles.Frame.Textbox.Text="Testing Done" print(tostring(part).." was hit by"..tostring(hitBy).."!") end
part.Touched:connect(action)
|
|
|
| Report Abuse |
|
|
| |
|
|
| 03 Apr 2014 05:40 AM |
Put the script below in StarterGui.
local item = Workspace.TouchedPart local player = script.Parent.Parent
function touched(hit) player.PlayerGui.Subtitles.Frame.TextBox.Text = "Testing Done" end
item.Touched:connect(touched) |
|
|
| Report Abuse |
|
|
|
| 04 Apr 2014 08:52 AM |
Can you please explain the script to me and make it re usable? thanks.
~Only fools jump in where the angels fear to tread~ |
|
|
| Report Abuse |
|
|