I am trying to make a block that once it is touched, makes a character change their team and clones a frame which shows the player a message. My issue is that when I touch this block, nothing happens. My player is detected, but nothing else seems to work.
script.Parent.TriggerUnemploymentCafe.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local character = humanoid.Parent
local localPlayer = Players:GetPlayerFromCharacter(character)
localPlayer.Team = TeamService.PoliceOfficer
if CheckTeam(localPlayer) == TeamService.CafeWorker
then
if localPlayer.PlayerGui.gameResponse:FindFirstChild("WarnUnemployed") then return end
else
local UnemployedMessage = localPlayer.PlayerGui.gameResponse.WarnCharacter:Clone()
UnemployedMessage.Title.Text = "You are now unemployed because you left the area. Return to the cash register to keep your job."
UnemployedMessage.ContinueButton.MouseButton1Down:Connect(function()
UnemployedMessage:Destroy()
UnemployedMessage.Name = "WarnUnemployed"
end)
end
end
end)
I believe @12904 is referring to your indentation levels. Take a look at this topic I put up about formatting your code when requesting support, primarily the indentation one.
What do you expect to happen with your code? You say that your player is detected but how do you know this exactly.
I reformatted the code while trying to dissect the problem. I hope that helps.
script.Parent.TriggerUnemploymentCafe.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local character = humanoid.Parent
local localPlayer = Players:GetPlayerFromCharacter(character)
localPlayer.Team = TeamService.PoliceOfficer
if localPlayer.Team == TeamService.CafeWorker then
if localPlayer.PlayerGui.gameResponse:FindFirstChild("WarnUnemployed") then return end
else
local UnemployedMessage = localPlayer.PlayerGui.gameResponse.WarnCharacter:Clone()
UnemployedMessage.Title.Text = "You are now unemployed because you left the area. "..
"Return to the cash register to keep your job."
UnemployedMessage.ContinueButton.MouseButton1Down:Connect(function()
UnemployedMessage:Destroy()
UnemployedMessage.Name = "WarnUnemployed"
end)
end
end
end)
I printed the LocalPlayers userId with success, and I also printed that the humanoid was found after the line local humanoid = hit.Parent:FindFirstChild("Humanoid")
Yes they can. The only difference is that client changes to Guis and the PlayerGui container do not replicate to the server and it’s bad practice to handle Guis from the server for anything other than cloning Guis there.
Ok, I made the script fire an event to change the playerGui. I am now realizing that the team is not detected, an issue I constantly have while scripting. What should I do? I am sure that my players team is CafeWorker, it prints as cafe worker and another part when touched makes my players team cafeworker.
What do you mean by the team is not detected? Is TeamService == game:GetService("Teams")? If you’re looking to find the player’s team, use localPlayer.Team as shown in @goldenstein64’s message.
nevermind, just received output but now i have the issue of my remoteevent being fired yet nothing happens… I literally can’t get remoteevents to work no matter how hard I try
script.Parent.TriggerUnemploymentCafe.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local character = humanoid.Parent
local localPlayer = Players:GetPlayerFromCharacter(character)
if localPlayer.Team == TeamService.CafeWorker then
local changeTextGui = Instance.new("RemoteEvent")
changeTextGui.Parent = game.ReplicatedStorage.Modules.Events
changeTextGui.Name = "changeText"
changeTextGui:FireClient(localPlayer)
end
end
end)
Here is my localscript:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local localPlayer = Players.LocalPlayer
local changeTextGui = ReplicatedStorage.Modules.Events
local playerGui = localPlayer:WaitForChild("PlayerGui")
local warnUnemployed = playerGui.gameResponse.WarnCharacter:Clone()
warnUnemployed.Title = "You are now unemployed because you left the area. Return to the cash register to keep your job."
warnUnemployed.Parent = playerGui.gameResponse
warnUnemployed.ContinueButton.MouseButton1Down:Connect(function()
warnUnemployed:Destroy()
end)
local function warningVisible()
warnUnemployed.Visible = true
end
changeTextGui.OnClientEvent:Connect(warningVisible)```