Hello devs currently I have an issue with my script.
I made a part when someone clicks on it a gui will pop up.Can somebody help?
Here is the script
script.Parent.ClickDetector.MouseClick:Connect(function(Click)
local Humanoid = Click.Parent:FindFirstChild("Humanoid")
if Humanoid then
local player = game.Players:GetPlayerFromCharacter(Click.Parent)
player.PlayerGui.StoryGui.ImageLabel.Visible = true
end
end)
The parameter that MouseClick event transfers is Player, not a part of character. Replace local humanoid with this: local Humanoid = Click.Character:FindFirstChild("Humanoid")
The mistake here is : local player = game.Players:GetPlayerFromCharacter(Click.Parent)
You can fix this easily by doing what @TheAOTKHolder said.
‘Click’ being the Player Instance means that you are taking the Player Instance’s Parent which would be Game.Players
However, I do not get the logic of your code as from what I am seeing, you are looking for the Player’s Humanoid (Child of Character) and then getting the Player instance from the character when it’s already given from the first argument (‘Click’).
On another note, you are making a change on the client’s GUI from the server which is not recommended.
Let me make some changes to your code so you can understand better :
--Script Detector Code
local button = script.Parent
button.ClickDetector.MouseClick:Connect(function(player)
--Fire a remote event to the client to change the Image's Visibility EXAMPLE BELOW
game.ReplicatedStorage.ImageEvent:FireClient(player) -- fires an event that changes image
end)
‘player’ is the player’s instance there that we’re using the fire the event to the client.
Now we need to code the event on a Local Script placed in the client, I will leave you an example below.
--Client Event Code
local plr = game.Players.LocalPlayer
local event = game.ReplicatedStorage.ImageEvent
local StoryGui = plr.PlayerGui:WaitForChild("StoryGui")
local Image = StoryGui:WaitForChild("ImageLabel")
event.OnClientEvent:Connect(function()
Image.Visible = true
end)