✓ Accepted answer
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)
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.
###Edit:
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 ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local screenGui = script.Parent
local function onToggleGui()
screenGui.Enabled = not screenGui.Enabled
end
remoteEvent.OnClientEvent:Connect(onToggleGui)
1 comment
is this a server script?