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

Why script wont work when part is touched, whats the point?

Asked by 6 years ago

Well, script is not working... It is not in Local Script... And it is freaking me out so please help here is the script... I opened Developer Console and it says PlayerGui is not valid member of Part I dont know what did I do wrong... I freak myself when I do something so long and it is not working... Well I'm trying to get answer on this question very long... And also I think that PlayerGui hates me... xD Please help!

function onTouched(theplayer)
    theplayer.PlayerGui.ScreenGui.OBJECTIVE_1.Enabled = true
end
script.Parent.Touched:connect(onTouched)

3 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

So, you may have gotten an error... Which you did and obviously, I noticed that you are using the players character to find the playerGui??????

this may not work but will give you an idea VVV

function Touch(PlayersBodyPart)
    local BodyPart = PlayerBodyPart -- using a simpler variable
    local Character = BodyPart.Parent -- the players character
    if Character:FindFirstChild("Humanoid") then -- if players character exists....
        local player = game:GetService("Players"):FindFirstChild(Character.Name) -- this should get the local player
        local GUI = player.PlayerGui.ScreenGui.OBJECTIVE_1
        GUI.Enabled = true
    end
end
script.Parent.Touched:connect(Touch)

I'm pretty sure this won't work ^^ Because I don't know how to get localplayer from scripts but i used a good strategy, there is a good chance it will work... Anyways, cya

EDIT: I would put the script as a localscript in startergui

local part = workspace.Part -- must be your part
local GUI = script.Parent.ScreenGui.OBJECTIVE_1

part.Touched:connect(function()
    if GUI.ClassName == "ScreenGui" then
        GUI.Enabled = true
    elseif GUI.ClassName == "Frame" then
        Gui.Visible = true
    end
end

This should work ^ it is untested but i bet it works

I need to see what your gui and part are and then I can make it happen for sure

0
Okay, let me try... AswormeDorijan111 531 — 6y
0
Well, it did not worked... AswormeDorijan111 531 — 6y
0
Is it a local script? NexanianStudios 91 — 6y
0
1) guis should not be changed with server scripts 2) local scripts dont run in workspace NexanianStudios 91 — 6y
View all comments (4 more)
0
If this new edit script doesn't work then I can't help you because there would be something wrong with your GUI greatneil80 2647 — 6y
0
Let me quicky set this to the localscript and put in StarterGUI. AswormeDorijan111 531 — 6y
0
Nope, its not working... Idk why did you put if GUI.ClassName == "ScreenGui" then GUI.Enabled = true elseif GUI.ClassName == "Frame" then Gui.Visible = true ... OBJECTIVE_1 is a ScreenGui... it is not in any other ScreenGui... Nothing is wrong with gui... AswormeDorijan111 531 — 6y
0
Because you can't enable a frame, you can only make it visible greatneil80 2647 — 6y
Ad
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

local plrName = nil local player = nil function onTouched(part) -- this is the part that touched the brick if (game.Players:FindFirstChild(part.Parent.Name)) then -- checks if part is a child of Player's Character plrName = part.Parent.Name -- sets 'plrName' to the Player's name who touched the brick player = game.Players:FindFirstChild(plrName) -- finds the Player in game.Players player.PlayerGui.ScreenGui.OBJECTIVE_1.Enabled = true end end script.Parent.Touched:connect(onTouched)
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

What you need to do is reference Players.


function onTouched(hit) If hit.Parent:FindFirstChild("Humanoid") then game.Players[hit.Parent.Name].PlayerGui.ScreenGui.OBJECTIVE_1.Enabled = true end end script.Parent.Touched:connect(onTouched)

If you don't, it will error on you

What you were doing is searching inside the part that touched the brick you want to be touched. So if your arm it it, it would search that

Answer this question