Enable ScreenGui OnTouch

Hello, the wonderful scripters. (o゚v゚)ノ
I’m working on a touch triggered cutscene for a secret ending when player touches teddy. I don’t have a problem with my cutscene, it plays when player touches the teddy.
I made a screengui and I want that it will be enabled when player touched the script.Parent.
It doesn’t wait the trigger and makes it enabled
I know, my script is wrong. Just I don’t how can I trigger the gui with a function.
Script is parented to handle. It is not a local script.

Script:

local cutsceneText = game.StarterGui.ScreenGui3
local function onTouch()
		cutsceneText.Enabled = true
		end
script.Parent.Touched:Connect(onTouch)

Rules:
•No making fun of me because of I can script the whole cutscene script but can’t script this easy script.

•Don’t yell at me if you explain and I don’t understand. Stay calm against my brain that doesn’t exist.

•Respect each other (●’◡’●)

I can give more information if you ask for it(≧∇≦)ノ

1 Like

The script.Parent is touched by another part besides a player so the function enables ScreenGui before any player activates the trigger. Also StarterGui is not a part of the current GUI of a player. Considering those two mistakes, you need this script instead:

local function onTouch(part)
	if part.Parent:FindFirstChildOfClass("Humanoid") ~= nil then
		game.Players:GetPlayerFromCharacter(part.Parent).PlayerGui.ScreenGui3.Enabled = true
	end
end

script.Parent.Touched:Connect(onTouch)
1 Like

script.parent.touched:connect(function)(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
onTouch()
end
end)

1 Like

Hey, it’s because you aren’t checking if a humanoid has touched the part. Instead it is touched by another part besides the player. I have edited your script and this should work:

local function OnTouch(Part)
	if Part.Parent:FindFirstChildOfClass("Humanoid") ~= nil then
		game.Players:GetPlayerFromCharacter(Part.Parent).PlayerGui.ScreenGui3.Enabled = true
	end
end

script.Parent.Touched:Connect(OnTouch)
1 Like

Thank you!
I got it, touched event checks every touch. To find if player touched it, checks humanoid isn’t nil.
Added a function to enable it correctly.
Thanks a lot again:D

1 Like

The first solution is yours, congrats!

1 Like

Thanks for your script but it is all wrong. You added the hit function and ended with onTouch.
Let me give an example for functions;

local function addNumbers(num1, num2)
	print(num1 + num2)
end

addNumbers(6, 3) 
addNumbers(5, 6) 

1 Like

oh sorry I didnt read the part that u said u wanted a function my bad

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.