So, I'm trying to make this GUI visible when you touch a brick.
Yes, I have tested this several times and the event is only triggered by a player as long as the brick does not get hit by an un-anchored brick.
The entire script is designed to be a Jumpscare that makes other blocks in the Workspace visible, and immediately after a Black GUI pops up. The script goes as follows:
local jumpp = game.Workspace.jumpp local dooropen = game.Workspace.Dooropen script.Parent.Touched:connect(function(player) script.Disabled = true jumpp.Head.Transparency = 0 jumpp.LeftArm.Transparency = 0 jumpp.LeftArmb.Transparency = 0 jumpp.LeftArmc.Transparency = 0 jumpp.LeftArmd.Transparency = 0 jumpp.RightArm.Transparency = 0 jumpp.RightArmb.Transparency = 0 jumpp.RightArmc.Transparency = 0 jumpp.RightArmd.Transparency = 0 jumpp.LeftLeg.Transparency = 0 jumpp.LeftLegb.Transparency = 0 jumpp.LeftLegc.Transparency = 0 jumpp.LeftLegd.Transparency = 0 jumpp.RightLeg.Transparency = 0 jumpp.RightLegb.Transparency = 0 jumpp.RightLegc.Transparency = 0 jumpp.RightLegd.Transparency = 0 jumpp.Torso.Transparency = 0 jumpp.Torsob.Transparency = 0 jumpp.Torsoc.Transparency = 0 jumpp.Torsod.Transparency = 0 wait(.1) game.Lighting.scare.Parent = player.PlayerGui dooropen.Window.Transparency = 1 dooropen.Windowinv.Transparency = 0 dooropen.Windowframe.Transparency = 1 dooropen.Windowframeinv.Transparency = 0 dooropen.DoorBottom.Transparency = 1 dooropen.DoorBottominv.Transparency = 0 dooropen.Window.CanCollide = false dooropen.Windowinv.CanCollide = true dooropen.Windowframe.CanCollide = false dooropen.Windowframeinv.CanCollide = true dooropen.DoorBottom.CanCollide = false dooropen.DoorBottominv.CanCollide = true jumpp:Destroy() end) --This is all written in a Regular Script.
According to the Output, the real issue is on line 28, the line where the GUI gets moved from Lighting to PlayerGui. "PlayerGui is not a valid member of Part" I'm not sure how it's incorrect. I used parameters in the function and specifically used them on line 28.
Thanks!
On line 28
, you can attempting to call PlayerGui
within the Model
/BasePart
type instance, NOT the Player
itself. This can be fixed, however, by using the GetPlayerFromCharacter method, also, on lines 6-26
, and lines 29-40
, that amount of code is not necessary, why not use a For loop to loop through all the Children
within the Parent
[within 'jumpp' and 'dooropen']? However, there is still three problems remaining; 1. What happens if the function fires multiple times 'onTouch'? 2. What if the 'BasePart' type instance that touches the 'BasePart' type instance is not a 'Player'? 3. Why is line 5
necessary? These problems, however, can be fixed, by checking if the thing touching it is indeed a 'Player', by using a 'Debounce' [to keep the function from firing multiple times], but however, I do not know what line 5
is necessary for, but, with all the fixes I have displayed, we can not recode, and fix your code;
local Debounce = false --This is our 'Debounce' now; This will prevent the function from firing multiple times 'onTouch' local jumpp = game.Workspace:WaitForChild("jumpp"); --Just realizing, why not use the 'WaitForChild' method? Because, what if 'jumpp' is not existant at the time of execution? local dooropen = game.Workspace:WaitForChild("Dooropen"); --Same problem that 'jumpp' had, which if 'Dooropen' was not existant at the time of execution? script.Parent.Touched:connect(function(hit) if Debounce or not game.Players:GetPlayerFromCharacter(hit.Parent) then return false end --Here is our 'Debounce' now; it will check to see if 'Debounce' is equal to 'true', and if it is, it will prevent the function from firing again, or, from firing multiple times 'onTouch', lastly, our method to get the 'Player', the 'GetPlayerFromCharacter event'! The 'if' statement will check to see if the current instance touching it is a 'Player' local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Variable/Identifier 'player' is now identifying 'player' as the 'Player' touching the Brick/Part Debounce = true --Reverts 'Debounce' to 'true', starting the prevention of the code from firing multiple times at once for i,v in pairs(jumpp:GetChildren()) do --Here is our 'for' loop now; It will loop through all the current 'Children' within 'jumpp' if v:IsA("BasePart") then --What if the current child [v] was not a 'BasePart' type instance? This will check to see if the current Child [v] is a 'BasePart' type instance v.Transparency = 0 --Will now revert the 'BasePart' type instances 'Transparency' property to '0', allow the 'Player' to see it end end game.Lighting.scare:Clone().Parent = player.PlayerGui --Instead of reverting the original's Parent to the Player's 'PlayerGui', why not 'Clone' it, then revert the 'Cloned' version into the 'PlayerGui'? for i,v in pairs(dooropen:GetChildren()) do if v:IsA("BasePart") then v.Transparency = 1 v.CanCollide = false end end wait(2) --Waits '2' seconds before going on Debounce = false --Reverts 'Debounce' to 'false' again, allowing a 'Player' to use the function again end)
Hope this helped!
You forgot that the argument for Touched
is the part that touches. So basically you are trying to go into whatever part that touched it and find PlayerGui inside of said part.
Also, you need to go to the Player, not the Character. You want to go to it's Parent then use GetPlayerFromCharacter()
which does what the name says.
Here's your script, if it doesn't work then just comment and I'll fix my error!
local jumpp = game.Workspace.jumpp local dooropen = game.Workspace.Dooropen script.Parent.Touched:connect(function(player) script.Disabled = true jumpp.Head.Transparency = 0 jumpp.LeftArm.Transparency = 0 jumpp.LeftArmb.Transparency = 0 jumpp.LeftArmc.Transparency = 0 jumpp.LeftArmd.Transparency = 0 jumpp.RightArm.Transparency = 0 jumpp.RightArmb.Transparency = 0 jumpp.RightArmc.Transparency = 0 jumpp.RightArmd.Transparency = 0 jumpp.LeftLeg.Transparency = 0 jumpp.LeftLegb.Transparency = 0 jumpp.LeftLegc.Transparency = 0 jumpp.LeftLegd.Transparency = 0 jumpp.RightLeg.Transparency = 0 jumpp.RightLegb.Transparency = 0 jumpp.RightLegc.Transparency = 0 jumpp.RightLegd.Transparency = 0 jumpp.Torso.Transparency = 0 jumpp.Torsob.Transparency = 0 jumpp.Torsoc.Transparency = 0 jumpp.Torsod.Transparency = 0 wait(.1) game.Lighting.scare.Parent = player.Parent:GetPlayerFromCharacter().PlayerGui dooropen.Window.Transparency = 1 dooropen.Windowinv.Transparency = 0 dooropen.Windowframe.Transparency = 1 dooropen.Windowframeinv.Transparency = 0 dooropen.DoorBottom.Transparency = 1 dooropen.DoorBottominv.Transparency = 0 dooropen.Window.CanCollide = false dooropen.Windowinv.CanCollide = true dooropen.Windowframe.CanCollide = false dooropen.Windowframeinv.CanCollide = true dooropen.DoorBottom.CanCollide = false dooropen.DoorBottominv.CanCollide = true jumpp:Destroy() end) --This is all written in a Regular Script.