Ok so I have this script that when you click it, it says "Taken by <name of the player who clicked>!"but it says click is a nil value. This usually works with touched events and clickedetector but its not working with gui clicks, so I'm looking for a way to check the name of the player who clicked it. Here is my script.
local function OnClick(Click) script.Parent.TakenBy.Text = ("Taken by"..(Click.Parent.Name).."!") end script.Parent.MouseButton1Click:Connect(OnClick)
I have a click parameter in my function, yet the output says click is a nil value. I also can't write "LocalPlayer.Name" because that only works in a local script, and I need the whole server to see this change. A localscript of course can't change it for the entire server because filtering is enabled. Does anyone have any ideas on how to solve this?
Errors:
The GuiButton.MouseButton1Click
event has no parameters.
In line 2, you wrapped your string in brackets, remove them since they are math exclusive, and arithmetic cannot be performed on a string. And in general they are just plain redundant.
I will rewrite your script, with a RemoteEvent
.
-- RemoteEvent coding, server side. game.Workspace.RemoteEvent.OnServerEvent:Connect(function(plr) local m = Instance.new("Message", game.Workspace) m.Text = "Taken by: "..plr.Name.."!" --See, no brackets? I would get an error if used. wait(5) m:Destroy() end)
Client-side code.
script.Parent.MouseButton1Click:Connect(function() game.Workspace.RemoteEvent:FireServer() end)