What do you want to achieve?
I want to get the player when the button is clicked
What is the issue?
When I try to print the player from the script, it prints out as nil:
partyBox.MouseButton1Click:Connect(function(player)
print(player)
end)
What solutions have you tried so far?
I’ve tried to look at the dev forums but couldn’t find any
(This is in a server script)
1 Like
Mirbah
(Mirbah)
December 26, 2024, 9:43pm
#2
try in a local script
partyBox.MouseButton1Click:Connect(function()
print(game.Players.LocalPlayer.Name)
end)
I cant put this in a local script because im cloning a button and detecting which player is clicking it so it can get sent to a specific party.
Full script if needed:
local frame = script.Parent
game.ReplicatedStorage.CreateParty.OnServerEvent:Connect(function(plr)
if plr.RegularValues.PartyCreation.Value == false then
game.ServerStorage.ServerValues.Servers.Value += 1
local val = game.ServerStorage.ServerValues.Servers.Value
local players = {plr.Name}
local partyBox = frame.PartyExample:Clone()
partyBox.Parent = frame
partyBox.Visible = true
partyBox.Position = UDim2.fromScale(0.046, 0.013 + (val - 1)*0.060)
partyBox.Name = "PartyBox"
partyBox.Text = plr.Name.. "'s Party (1/5)"
partyBox.MouseEnter:Connect(function()
partyBox.BackgroundTransparency = 0.4
end)
partyBox.MouseLeave:Connect(function()
partyBox.BackgroundTransparency = 0.6
end)
print(players)
partyBox.MouseButton1Click:Connect(function(player)
print(player)
if player.RegularValues.PartyCreation.Value == false then
table.insert(players, player)
end
end)
end
end)
I think it not possible to get player’s name . Because you can’t get player’s name in MouseButton1Click. Try another way i think
I’m assuming you are working on a UI so you could just .Parent your frame until you reach the player, since all UI is located in PlayerGui folder, which is located inside the player.
With that being said, i’m pretty sure changing UI through server is bad practice. UI itself is a client-side thing sooo yeah.
you would never do this inside a server script.
if you need to make the client create or clone a frame when the server tells so, then you should just use a RemoteFunction
this is horrible (considering you’re doing that on the server)
i recommend you to look at some tutorials
1 Like