Hello! I want to detect the player who clicked on a cash register in order to find the player’s name who clicked the button so I used local player in a local script. Once I got the name, I saved it into a string value in a local script as expected. However, it doesn’t show up in the server so how can I solve this problem because I need all players to access it
When setting a value via a local script, it will not replicate to the server automatically. The simplest way to do this is to insert a clickdetector inside your cash register and set the player name using the given parameter within a MouseClick event.
Example:
local clickDetector = script.Parent
local function onClicked(player)
—check if cash register doesn’t have name assigned to it
—If not, set the cash register string value
end
clickDetector.MouseClick:Connect(onClicked)
So I use remote events? I mean I have it set up already just that I didn’t use it to save the player name
When using clickdetectors you can find who clicked it from a server script so there is no need for a local script or remote event.
When a player clicks on a clickdetector and you connect it being clicked to a function it automatically gives you the player.
You can read up on it here from the MouseClick event
local clickDetector = script.Parent
local function onClicked(player)
-- Show a message to the player
local msg = Instance.new("Message")
msg.Parent = player:FindFirstChild("PlayerGui")
msg.Text = "Hello, " .. player.Name
wait(2.5)
msg:Destroy()
end
-- Connect the function to the MouseClick event
clickDetector.MouseClick:Connect(onClicked)```
Ty I managed to fix it using Remote Events!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.