How can I make the GUI appear when a player comes in contact with a brick and then go away when they move away from it. Someone told me it was with magnitudes but I tried it out and it didn't work for some reason. Since nothing popped up.
function touch(hit) if game.Players:findFirstChild(hit.Parent.Name) ~= nil then local player = game.Players[hit.Parent.Name] if player.PlayerGui:findFirstChild("Shop") == nil then local gui = script.Shop:clone() gui.Parent = player.PlayerGui repeat wait() until (player.Character.Torso.Position - script.Parent.Position).magnitude > 5 gui:remove() end end end script.Parent.Touched:connect(touch)
I don't think the way you are approaching this is a very efficient way, while server scripts are good for a lot of things, meddling with the player GUI isn't one of those. You should really just use a local script to make it a little easier. The reason being that server scripts can't directly modify the player GUIs. I say directly because server scripts can still give input through remote events, but those aren't necessary for this purpose.
To accomplish this in a local script, you have to :
1) Have a touched event to sense if something touched a part
2) Check if the thing that hit the part is a descendant of the character of the local player
3) Move a GUI on the screen
4) wait a given amount of time, then move it off the screen
If you want to have a smooth transition, I'd recommend using tween service or the TweenPosition function of GUI elements.
local player = player.Players.LocalPlayer local frame = script.Parent workspace.Part.Touched:Connect(function(hit) -- 1 if hit:IsDescendentOf(player.Character) then --2 frame:TweenPosition(UDim2.new(0.3,0,.3,0))--3 wait(2)--4 frame:TweenPosition(UDim2.new(1,0,1,0))--4 end end)
you can also change around the aesthetics of the tween by modifying the TweenPositon function:
GUI:TweenPosition(Udim2pos,easingDirection,easingStyle,time,overidable )
Ex: gui:TweenPosition(Udim2.new(0,0,0,0),Enum.EasingDirection.In,Enum.EasingStyle.Sine,2,true)
Use Visible unstead of remove, this is only for text boxes, text buttons, etc.
function touch(hit) if game.Players:findFirstChild(hit.Parent.Name) ~= nil then local player = game.Players[hit.Parent.Name] if player.PlayerGui:findFirstChild("Shop") == nil then local gui = script.Shop:clone() gui.Parent = player.PlayerGui repeat wait() until (player.Character.Torso.Position - script.Parent.Position).magnitude > 5 gui.Visible = false end end end script.Parent.Touched:connect(touch)