Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GUI wont become visible after player walks on part?

local player = game.Players.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local GUI = script.Parent

replicatedStorage.remeve.OnClientEvent:Connect(function(Boolean)
       if Boolean and GUI then
             GUI.Enabled = Boolean
       end
end)

This LocalScript inside the ScreenGui is supposed to appear when a player steps on a part, then dissapear when the player walks away from the part. It says fireserver can only be activated by the client for the error, the error comes from this script using the remote event too thats in the part:

local part = script.Parent

part.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player then return end 
     game:GetService("ReplicatedStorage").remeve:FireServer(player,true) 
      end
end)

part.TouchEnded:Connect(function (hit)
       if hit.Parent:FindFirstChild("Humanoid") then
             local player = game.Players:GetPlayerFromCharacter(hit.Parent)
             if not player then return end
            game:GetService("ReplicatedStorage").remeve:FireServer(player,false)         
       end
end)

4 answers

✓ Accepted answer

I don't think handling touched events on the client is a good idea, instead use a remote event and call it to the client to show the UI, insert a remote event in ReplicatedStorage and name it whatever, then put a script in your part that will enable the UI

-- a normal script inside the part that enables ur GUI
local part = script.Parent

part.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
            -- it's a Character
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player then return end -- if it's an NPC then don't do anything
     game:GetService("ReplicatedStorage").RemoteEventHere:FireClient(player,true) -- the second parameter will be useful later on
      end
end)

part.TouchEnded:Connect(function (hit)
       if hit.Parent:FindFirstChild("Humanoid") then
             local player = game.Players:GetPlayerFromCharacter(hit.Parent)
             if not player then return end
            game:GetService("ReplicatedStorage").RemoteEventHere:FireClient(player,false)         
       end
end)

Now for the localscript, if you have a normal script in your GUI, delete it and insert a localscript and we are gonna be using the Onclientevent which runs for the player you referenced in your first parameter

-- LocalScript inside your ScreenGui, has to be a localscript or it doesn't work
local player = game Player.LocalPlayer
local replicatedStorage = game:GetService("ReplicatedStorage")
local GUI = script.Parent

replicatedStorage.RemoteEventNameHere.OnClientEvent:Connect(function(Boolean) -- the first parameter is the true or false we sent
       if Boolean and GUI then
             GUI.Enabled = Boolean
       end
end)

Ignore the weird indentation, I'm on mobile

5 comments

0

ok so the only error that pops up is that fire server can only be fired by client, thats probably why it does not work

0

Oh I'm sorry, I made a typo

0

It should be FireClient, not fireserver, try now

0

ok, it now becomes visible, but now cant become invisible when u leave the part

0

ok, it now becomes visible, but now cant become invisible when u leave the part

I see what you're trying to do, you were close but not quite there. Currently your using the client to define the player, and not actually the player who is touching it.

local Part = workspace:WaitForChild('Business').HandShop.EnterHandShop
local Player = game:GetService('Players').LocalPlayer
local UI = script.Parent

Part.Touched:Connect(function(hit)
	local victim = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if victim == Player then
		UI.Visible = true
	end
end)

Part.TouchEnded:Connect(function(hit)
	local victim = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if victim == Player then
		UI.Visible = true
	end
end)

3 comments

0

i tried it in studio and the gui doesnt appear

0

Ah, apologies. I should of changed visible to enabled. Visible is for most UI elements, as for ScreenGui is enabled since it holds the other UI elements.

0

ima break your 999 point thing and ima make it 1000+ hahhaha by upvoting your question

Solution Simple fix


local Part = game.Workspace:WaitForChild('Business').HandShop.EnterHandShop
local Player = game.Players.LocalPlayer
local UI = script.Parent


Part.Touched:Connect(function(hit)
	local victim = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if victim == Player then
		UI.Enabled = true
		
	end
end)

Part.TouchEnded:Connect(function(hit)
	local victim = game:GetService('Players'):GetPlayerFromCharacter(hit.Parent)
	if victim == Player then
		UI.Enabled = false
		
	end
end)

Issues: UI.Enabled not UI.Visible, The second UI.Enabled was true, which should be false


Works like a charm

7 comments

0

doesnt work and doesnt print an output

0

more like a broken charm

0

oh

0

are you using a local script?

0

It worked perfectly for me

0

i am using a regular script

0

you have to use a local script when doing screen gui's, because the only thing that can see it is the client, not the server, the server uses regular scripts

Here's a solution:

-- part script w/ touched events

local part = script.Parent

part.Touched:Connect(function(hit)
      if hit.Parent:FindFirstChild("Humanoid") then
            local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if not player then return end 
     game:GetService("ReplicatedStorage").remeve:FireClient(player,true) 
      end
end)

part.TouchEnded:Connect(function(hit)
       if hit.Parent:FindFirstChild("Humanoid") then
             local player = game.Players:GetPlayerFromCharacter(hit.Parent)
             if not player then return end
            game:GetService("ReplicatedStorage").remeve:FireClient(player,false)         
       end
end)
-- local script in starterGui

local player = game.Players.LocalPlayer -- as far as i see, you haven't really used this variable so you can remove it if you want
local replicatedStorage = game:GetService("ReplicatedStorage")
local GUI = game.ReplicatedStorage.GuiName -- place your gui in ReplicatedStorage

replicatedStorage.remeve.OnClientEvent:Connect(function(Boolean)
       if Boolean and GUI then
             GUI.Parent = script.Parent 
	elseif not Boolean then
		GUI.Parent = replicatedStorage
       end
end)

1 comment

0

no

This discussion is preserved as it was. New answers, comments, and votes are closed.