function onTouched() game.starterGui.ScreenGui.Frame:TweenPosition(UDim2.new(0.5, -250,0, 0)) end script.Parent.onTouched:connect()
Your problem is a common mistake that many people make assuming that StarterGui changes all Player Guis. This is however not the case, since the StarterGuis are basically copied into the PlayerGui object of the Player. You also have no way of identifying if a player is hitting the brick, thus leaving the script not knowing what to do. Your script is also trying to identify "OnTouched" as an event, which it is not a valid event.
There are a couple solutions, one involving FilteringEnabled being Disabled and FilteringEnabled being Enabled.
With FilteringEnabled being Disabled, the server has more flexibility with what it can do with the client. Meaning you're able to manipulate GUIs through the server. With the Touched event, it provides the part that hit the brick being listened to. So we can try to identify the player through that using :GetPlayerFromCharacter()
from the Players Service.
function OnTouched(objectThatHit) if objectThatHit.Parent:FindFirstChild('Humanoid') then --If there is a humanoid in the object's parent, then we know it's probably a character model. local player = game:GetService('Players'):GetPlayerFromCharacter(objectThatHit.Parent) --We should have the player by now. So we'll access it's PlayerGui. player.PlayerGui.ScreenGui.Frame:TweenPosition(UDim2.new(.5,-250,0,0)) end end script.Parent.Touched:connect(OnTouched)
This script can go in a Server-Sided Script, inside the part that would need to be touched for the Gui to pop up. With FilteringEnabled Disabled. If all three fields are not met, the script will likely throw an error.
With FilteringEnabled Enabled, the server is restricted with use of PlayerGuis of Players. Which for this case, you would need to use a LocalScript.
For this to work, you would need to name the part that needs to be hit uniquely. That way the script doesn't confuse a part with another part.
And for this script, you do not need to use the GetPlayerFromCharacter method. You can simply use the LocalPlayer value of Players.
function OnTouched() game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame:TweenPosition(UDim2.new(.5,-250,0,0)) end game.Workspace.PartNameThatNeedsToBeHitHere.Touched:connect(OnTouched)
Kind of what Andorks was trying to do with his code. You would need to have this script in a LocalScript in the PlayerGui, Backpack, PlayerScripts, or the Player's Character. Otherwise this script will not work.
You're making a common mistake. It is seen pretty easily. As you can tell below, this is in-correct:
function onTouched() game.starterGui.ScreenGui.Frame:TweenPosition(UDim2.new(0.5, -250,0, 0)) end script.Parent.onTouched:connect()
Not only are you trying to tween the Gui in StarterGui, but "script.Parent.onTouched" is not a event. You should use "script.Parent.Touched:connect(onTouched)" The code below should fix your problems:
function onTouched() game.Players.LocalPlayer.PlayerGui.Frame:TweenPosition(UDim2.new(0.5, -250,0, 0)) end script.Parent.Touched:connect(onTouched)
Please click accept my answer, and rate me up! ;) If it doesn't, please message me!