Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

8 comments

0

Okay, let me try...

0

Well, it did not worked...

0

Is it a local script?

0
  1. guis should not be changed with server scripts 2) local scripts dont run in workspace
0

If this new edit script doesn't work then I can't help you because there would be something wrong with your GUI

0

Let me quicky set this to the localscript and put in StarterGUI.

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...

0

Because you can't enable a frame, you can only make it visible


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)

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

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