For some reason it isn't working, it says "trying to index a nil value PlayerGui."
I checked and everything is working except 'game.Players.name.PlayerGui.BoatSpawn.Enabled = true'
I also checked what 'name' returns and it is working.
local Part = script.Parent Part.Touched:connect(function(HIT) local H = HIT.Parent:FindFirstChild("Humanoid") if H then local Player = game.Players:GetPlayerFromCharacter(HIT.Parent) local name = H.Parent.Name game.Players.name.PlayerGui.BoatSpawn.Enabled = true end end)
It is in a script in a part in the workspace.
The problem is how you use variable name
to get the player. To properly index you use [ ] brackets after the parent you're indexing.
On line 08 it should be:
game.Players[name].PlayerGui.BoatSpawn.Enabled = true
There are two problems with this. One being that you're trying to access something in playergui through a server Script. Server scripts do not have access to the PlayerGui so you will need to use a local script to edit BoatSpawn if it's a ScreenGui or GuiObject.
The second problem is,
Why index the player when you get them on line 06 using :GetPlayerFromCharacter()
? You can simplify your code by removing lines 07 and 08:
local Player = game.Players:GetPlayerFromCharacter(HIT.Parent) --Player.PlayerGui.BoatSpawn.Enabled = false
Again, the first problem still stands here since you should have the client handle the Gui. See RemoteEvents if you want to see how to get by this.
The reason you need a RemoteEvent here is because the server cannot see the ScreenGui in the PlayerGui. You need to communicate with the client (Which does see the Gui) to change it's properties.
To go about this you will need a RemoteEvent in ReplicatedStorage, the same Touched script I gave you and a local script in the ScreenGui we're editing.
local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage.RemoteEvent local Part = script.Parent local debounce = false Part.Touched:Connect(function(HIT) if debounce then return end debounce = true local human = HIT.Parent:FindFirstChildOfClass("Humanoid") if human then local Player = game.Players:GetPlayerFromCharacter(HIT.Parent) remoteEvent:FireClient(Player) wait(3) end debounce = false end)
I included a debounce to prevent event spam.
Then in the client we listen for the RemoteEvent to go off using OnClientEvent
.
--local script in ScreenGui we want to toggle local ReplicatedStorage = game:GetService("ReplicatedStorage") local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent") local screenGui = script.Parent --The parent of this script should be the ScreenGui --not is a handy substitute here so we don't use messy if-statements. local function onToggleGui() screenGui.Enabled = not screenGui.Enabled end remoteEvent.OnClientEvent:Connect(onToggleGui) --Connect to the function