So basically I want like to know from when a player touches a part a GUI only appears once and after that the script disables but only for the client, like only the player who touched the part, and I want to do when you touch the part again the GUI doesn’t pop up and when u rejoin and touch the part, the GUI doesn’t pop up too.
Here is a simple example/idea:
--Local script
local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
local Part = workspace:WaitForChild("Baseplate")
local Debounce = false
Part.Touched:Connect(function(Object)
if not Object.Parent:FindFirstChild("Humanoid") and not Players:FindFirstChild(Object.Parent.Name) then return end
local real = Players:GetPlayerFromCharacter(Object.Parent)
if Debounce == false then
Debounce = true
if real == Player then
Replicated:WaitForChild("SendData"):FireServer()
end
task.wait(3)
Debounce = false
end
end)
--Server Script
local Players = game:GetService("Players")
local Replicated = game:GetService("ReplicatedStorage")
local DataStore = game:GetService("DataStoreService")
Replicated:FindFirstChild("SendData").OnServerEvent:Connect(function(Player)
--Clone a GUI here, parent it to Player.PlayerGui, and set the player datastore.
end)
Example:
You would want to use a RemoteEvent because RE’s can communicate between separate scripts using certain events. Put the RemoteEvent under ReplicatedStorage . Make sure to make a GUI and put it in StarterGui, change enabled to false
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.Touched:Connect(function(touched)
if game.Players:FindFirstChild(touched.Parent.Name) then
local player = game.Players:FindFirstChild(touched.Parent.Name)
RE:FireClient(player)
end
end)
Basically just ensuring that whatever touched the part is an actual player, if it is an actual player it will fire the RemoteEvent.
Do the following in a LOCAL SCRIPT and put it in anywhere that is appropriate to be a parent of a local script, EX: StarterPack, StarterPlayerScripts, etc. Just don’t put it in ServerScriptService.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")
local StarterGui = game:GetService("StarterGui")
local gui = StarterGui:WaitForChild("yourGuiHere")
RE.OnClientEvent:Connect(function(player)
gui.Enabled = true
end)
Hope this helps!
The following will work even when the player leaves in the same server.
1 . Create a RemoteEvent in ReplicatedStorage and name it Client
2 . Change the path of the variable Gui in the localscript to your gui path.
ServerScript :
--\\Variables//--
local PlayersTable = {}
local RemoteEvent = game.ReplicatedStorage.Client
local Part = game.Workspace.YourPart
--\\Main Code//--
Part.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if table.find(PlayersTable,plr.Name) then return end -- Checks if the player already touched the part before
table.insert(PlayersTable,plr.Name)
Client:FireClient(plr)
end)
LocalScript :
local RemoteEvent = game.ReplicatedStorage.Client
local plr = game.Players.LocalPlayer
RemoteEvent.OnClientEvent:Connect(function()
local Gui = plr.PlayerGui
plr.PlayerGui.YourGui.Frame.Visible = true
wait(4)
plr.PlayerGui.YourGui.Frame.Visible = false
end)
Popup = script.Parent.ScreenGui
Ready = false
function onTouch(hit)
local h = hit.Parent:FindFirstChild(“Humanoid”)
if not Ready then
Ready = true
local plyr = game.Players:FindFirstChild(h.Parent.Name)
local c = Popup:clone()
c.Parent = plyr.PlayerGui
wait(3)
c:remove()
wait(4)
script.Disabled = true
end
end
script.Parent.Touched:connect(onTouch)
I have that and I just wanna know if y’all can like change anything in it I put my gui in my part but this only works once but when u rejoin u see it so
Server Script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")
script.Parent.Touched:Connect(function(touched)
if game.Players:FindFirstChild(touched.Parent.Name) then
local player = game.Players:FindFirstChild(touched.Parent.Name)
RE:FireClient(player)
end
end)
Put in StarterPlayerScripts
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RE = ReplicatedStorage:WaitForChild("RemoteEvent")
local StarterGui = game:GetService("StarterGui")
local gui = StarterGui:WaitForChild("yourGuiHere")
local Used = false
RE.OnClientEvent:Connect(function(player)
Used = true
gui.Enabled = true
end)
What do you mean by that? I’m like new to scripting
no, that will not work when the player leaves.
Hmm but it worked in my game O_O
The following will work even when the player leaves.
1 . Create a RemoteEvent in ReplicatedStorage and name it Client
2 . Make a Script and put it in ServerScriptService
Server Script :
--\\Variables//--
local PlayersTable = {}
local RemoteEvent = game.ReplicatedStorage.Client
local Part = game.Workspace.YourPart
--\\Main Code//--
Part.Touched:Connect(function(hit)
if not hit.Parent:FindFirstChild("Humanoid") then return end
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if table.find(PlayersTable,plr.Name) then return end -- Checks if the player already touched the part before
table.insert(PlayersTable,plr.Name)
Client:FireClient(plr)
end)
3 . Make a localscript and put it in StarterCharacterScripts.
local RemoteEvent = game.ReplicatedStorage.Client
local plr = game.Players.LocalPlayer
RemoteEvent.OnClientEvent:Connect(function()
local Popup = game.StarterGui.ScreenGui
Popup:Clone().Parent = plr.PlayerGui
wait(4)
Popup:Destroy()
end)
The thing is per each part I want it to show different like text on the gui
Does it like work for per each part there is a different textlabel?
if you want it for each part why don’t you just delete the whole part for the client.
You said that you want the gui to appear and not a text label
I’m making a obby, when you complete a stage it says for example on stage 22 “You completed stage 22” but I hate like each time when I join it keeps saying that, so I don’t know
ye a gui and in the gui there is a textlabel
in this case you would need to use datastore.
but you don’t really need all of this
since you can already fix that in the stage script.
if Player.Stage.Value > CurrentCheckPoint.Value then
-- Show Text
end
I already have a datastore to save it, I only like to need to fix the GUI, If you want to help. I’m not forcing you. I’m just kinda new to scripting so I’m like confused.
as i said in your checkpoint or stages script
you probably have an if statement to check if the Player’s CurrentStage & His current checkpoint are equal
This is my stages script:
local checkpoints = workspace:WaitForChild(“Checkpoints”)
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local stage = Instance.new("IntValue")
stage.Name = "Stage"
stage.Value = 1
stage.Parent = leaderstats
player.CharacterAdded:Connect(function(char)
local hum = char:WaitForChild("Humanoid")
wait()
char:MoveTo(checkpoints[stage.Value].Position)
hum.Touched:Connect(function(hit)
if hit.Parent == checkpoints then
if tonumber(hit.Name) == stage.Value + 1 then
stage.Value = stage.Value + 1
end
end
end)
end)
end)
and this is my datastore script:
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore = DataStoreService:GetDataStore(“Stage”)
game.Players.PlayerAdded:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = myDataStore:GetAsync(player.UserId)
end)
if success then
player.leaderstats.Stage.Value = data
else
warn(errorMessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local data
local success, errorMessage = pcall(function()
data = myDataStore:SetAsync(player.UserId, player.leaderstats.Stage.Value)
end)
if success then
print("Data Saved")
else
warn(errorMessage)
end
end)
game:BindToClose(function()
for i, v in pairs(game.Players:GetChildren()) do
v:Kick(“Server Closed”)
end
wait(2)
end)