This script that I made is supposed to tween a Frame in a GUI when you touch a brick, but I keep getting this error:
attempt to index a nil value.
This makes no sense, because the GUI is in "PlayerGui". Also this script works in studio and not in the game itself..
script.parent.Touched:Connect(function(m)
local player = game.Players:GetPlayerFromCharacter(m.Parent);
wait(0.1)
player.PlayerGui:WaitForChild("Teleport").Frame:TweenPosition(UDim2.new(0,0,0,0), "Out", "Linear", 1)
end
Any help would be appreciated.

1 comment
Use a LocalScript to handle guis