What do you want to achieve? Keep it simple and clear!
I want this script to find the player name of the player who clicked the button of a gui in the workspace.
What is the issue? Include screenshots / videos if possible!
I cant find a working way to get the player that clicked the the button.
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried to use parameter “player” with the function, but that did not work.
As stated earlier, this GUI button is inside of workspace and this script is a sever script
local module = require(game.ServerScriptService.StaffNotifyModule)
local button = script.Parent
function onClicked(player)
local playername = player.Parent.Name
module.Notify("Notif", playername.. " has clicked a staff button")
end
button.MouseButton1Click:Connect(onClicked)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
local module = require(game.ServerScriptService.StaffNotifyModule)
local button = script.Parent
function onClicked()
local player = script:FindFirstAncestorWhichIsA('Player')
local playername = player.Name
module.Notify("Notif", playername.. " has clicked a staff button")
end
button.MouseButton1Click:Connect(onClicked)
The script worked fine for me, the only thing I changed are the module parts.
--local module = require(game.ServerScriptService.StaffNotifyModule)
local button = script.Parent
function onClicked()
local player = script:FindFirstAncestorWhichIsA('Player')
local playername = player.Name
--module.Notify("Notif", playername.. " has clicked a staff button")
print(playername)
end
button.MouseButton1Click:Connect(onClicked)
Just set it’s adornee to the part. But if you really don’t want to parent it to starter gui. Try using remote events.
-- local script (game.StarterPlayer.StarterPlayerScripts)
local re = game.ReplicatedStorage.ButtonClick
workspace.Part.SurfaceUI.Button.MouseButton1Click:Connect(function()
re:FireServer()
end)
-- server script (inside the button, or in server script service)
local Module = ...
local re = game.ReplicatedStorage.ButtonClick
re.OnServerEvent:Connect(function(Plr)
Module.Notify("Notif", Plr.Name, "has clicked a staff button")
end)
Edit : Keep in mind that this is quite unsafe as an exploiter could fire this remote event very easily, though I have no idea on how I can make it more secure.