Ive been trying to get a GUI to pop up whenever I enter an invisible block, using the Touch Event.
Heres the code:
touched = false
script.Parent.Touched:connect(function(hit)
if touched == false then
touched = true
if hit.Parent:findFirstChild("Humanoid") ~= nil then
local char1 = hit.Parent
player1 = game.Players:GetPlayerFromCharacter(char1)
end
--local TB = player1.PlayerGui.TalkButton
if player1.PlayerGui:findFirstChild("TalkButton") then
player1.PlayerGui.TalkButton.Grouper.Activator.Value = "Rabbit"
player1.PlayerGui.TalkButton.Grouper.Visible = true
end
end
end)
script.Parent.TouchEnded:connect(function(hit)
--[[char2 = hit.Parent
player2 = game.Players:GetPlayerFromCharacter(char2)]]
if hit.Parent:findFirstChild("Humanoid") then
local char1 = hit.Parent
player1 = game.Players:GetPlayerFromCharacter(char1)
end
--local TB = player1.PlayerGui.TalkButton
touched = false
if player1.PlayerGui:findFirstChild("TalkButton") then
player1.PlayerGui.TalkButton.Grouper.Visible = false
end
end)
Before I put the checks for Humanoid, I was getting an error, "Talkbutton is not located in PlayerGui". However, I place that Element inside the Startergui in studio, and when I check inside the player while in solo mode, its in PlayerGui. After I put the checks, the error stopped showing, but now it still wont change the visibility of the gui. Note, my script works perfectly fine in studio, and there were no errors with the TalkButton, but whenever I play the game from the website I've been receiving these problems.
The code is inside a Server Script that is inside the object which I want to touch.
Help, anyone?
