Problem with appearing gui when touched

i made a script that if someone touch it, it appears to a player but it appears to everyone, but i need it appear only for a guy who touched that, how do i make it?

and sorry for my grammar.

local function LeScriptoWhenTouched()
	script.Parent.Visible = true
end

local function LeScriptoWhenEndTouch()
	script.Parent.Visible = false
end

game.Workspace.Map.Plita.Touched:Connect(LeScriptoWhenTouched)
game.Workspace.Map.Plita.TouchEnded:Connect(LeScriptoWhenEndTouch)

Use a local script instead of a server script for a task like this.

2 Likes

In this criteria is hard to know where your gui is located but I am going to say that’s inside of a StarterGui. So just by looking at your source code I can see that you are missing a check if Humanoid exsits, that’s why script overpasses every touch even wtih another object. Here is a potential fix:

local function LeScriptoWhenTouched(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
	script.Parent.Visible = true
   end
end

local function LeScriptoWhenEndTouch(hit)
  if hit.Parent:FindFirstChild("Humanoid") then
	script.Parent.Visible = false
  end
end

game.Workspace.Map.Plita.Touched:Connect(LeScriptoWhenTouched)
game.Workspace.Map.Plita.TouchEnded:Connect(LeScriptoWhenEndTouch)

you right my gui located in StarterGui but your fix dont work it is still appearing for everyone

Then you will have to clone the GUI inside PlayerGui. Here is an example how to do it:

local CloneD = game:GetService("StarterGui"):WaitForChild("ScreenGuiNameHere")

local function LeScriptoWhenTouched(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
    local New = CloneD:Clone() 
	New.Parent = game:GetService("Players"):FindFirstChild(hit.Name):FindFirstChild("PlayerGui") -- Make sure it's visible by default
   end
end

local function LeScriptoWhenEndTouch(hit)
  if hit.Parent:FindFirstChild("Humanoid") then
	game:GetService("Players"):FindFirstChild(hit.Name):FindFirstChild("PlayerGui"):FindFirstChild("ScreenGuiNameHere"):Destroy()
  end
end

game.Workspace.Map.Plita.Touched:Connect(LeScriptoWhenTouched)
game.Workspace.Map.Plita.TouchEnded:Connect(LeScriptoWhenEndTouch)

Now its just giving me error
Error Message:
Players.Shakychn.PlayerGui.Poklon.Activate.TouchScript:6: attempt to index a nil value

local CloneD = game:GetService("StarterGui"):WaitForChild("Poklon")

local function LeScriptoWhenTouched(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
    local New = CloneD:Clone() 
	New.Parent = game:GetService("Players"):FindFirstChild(hit.Name):FindFirstChild("PlayerGui") -- Make sure it's visible by default
   end
end

local function LeScriptoWhenEndTouch(hit)
  if hit.Parent:FindFirstChild("Humanoid") then
	game:GetService("Players"):FindFirstChild(hit.Name):FindFirstChild("PlayerGui"):FindFirstChild("Poklon"):Destroy()
  end
end

game.Workspace.Map.Plita.Touched:Connect(LeScriptoWhenTouched)
game.Workspace.Map.Plita.TouchEnded:Connect(LeScriptoWhenEndTouch)

My bad instead of calling hit.Name call it hit.Parent.Name on both functions.

local CloneD = game:GetService("StarterGui"):WaitForChild("Poklon")

local function LeScriptoWhenTouched(hit)
   if hit.Parent:FindFirstChild("Humanoid") then
    local New = CloneD:Clone() 
	New.Parent = game:GetService("Players"):FindFirstChild(hit.Parent.Name):FindFirstChild("PlayerGui") -- Make sure it's visible by default
   end
end

local function LeScriptoWhenEndTouch(hit)
  if hit.Parent:FindFirstChild("Humanoid") then
	game:GetService("Players"):FindFirstChild(hit.Parent.Name):FindFirstChild("PlayerGui"):FindFirstChild("Poklon"):Destroy()
  end
end

game.Workspace.Map.Plita.Touched:Connect(LeScriptoWhenTouched)
game.Workspace.Map.Plita.TouchEnded:Connect(LeScriptoWhenEndTouch)

Now its dont want to appear and there is no errors in output

Did you make Frame visible by default?

no but i did that already and something happening with background transparency and its still visible when you stop touching part

Oh well you also have to check if in PlayerGui, Gui already exsits so it doesn’t overloop the clone.

You need to do script this on a local script and access the player gui. You will have to do something like this

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local FrametoEnable = PlayerGui.--your ScreenGui.YourFrame
local EnablePart = -- locate the part you want to enable the gui when it's touched
local DisablePart  = --locate the part you want to disable the gui when it's touched

EnablePart.Touched:Connect(function(hit)
     if hit.Parent:FindFirstChild("Humanoid") then
           FrametoEnable.Visible = true
      end
end)
DisablePart.TouchEnded:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
           FrametoEnable.Visible = false
      end
end)

Also local scripts run on the client and and server scripts are server sided.

If your code is in a ServerScript then try to fire it to the client using :FireClient()

You get the character/player that touched the part using the arguments you got from the :Touched() event.
Then, you check if player name in the script is equal to player name that touched the part.
That’s the easiest way to do it without making tremendous changes to the script.

Your script basically wrote that if something touches the part, the gui will appear and not if you touches the part, the gui will appear, so you need to fix that.

1 Like

This might help you :slight_smile:

Search after the [ Server to Client ]