Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I get the players name that clicked the "MainDetector" and use that in the script?

Asked by
N33H 19
4 years ago
Edited 4 years ago

I have a script that towards the bottom says localplayer but i know a script cant use local player, so how would i find the name of the player that clicked the detector and use that instead of localplayer?

-- Variables --

    local scriptFolder = script.Parent
    local partFolder = script.Parent.Parent.PartsAndSound

-- Scripting --

    partFolder.Enable.MainDetector.MouseClick:Connect(function()
        partFolder.Enable.Printer:Play()
            wait(0.1)
                partFolder.Enable.MainDetector:Destroy()
                    scriptFolder.isPrinting.Value = true
                        wait(1)
                            scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
                        wait(2)
                            partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
                                partFolder.Enable.PrintedCash:Play()
                        wait(1)
                            scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
                        wait(2)
                            partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
                            partFolder.Enable.PrintedCash:Play()
                            wait(1)
                            scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
                        wait(2)
                            partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
                            partFolder.Enable.PrintedCash:Play()
                            wait(1)
                            scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
                        wait(2)
                            partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
                            partFolder.Enable.PrintedCash:Play()
                            partFolder.Enable.SecondaryDetector.MaxActivationDistance = 15
                            wait(1)
                            scriptFolder.CP3M.Value = scriptFolder.CP3M.Value + 3000
                        wait(2)
                            partFolder.CashPrinted.SurfaceGui.CashPrinted2.Text = scriptFolder.CP3M.Value
                            partFolder.Enable.PrintedCash:Play()
                            partFolder.Enable.SecondaryDetector.MaxActivationDistance = 15


                                if scriptFolder.CP3M.Value == 15000 then
                                    partFolder.Enable.SecondaryDetector.MouseClick:Connect(function()
                                        game.Players.(PLAYERNAME).leaderstats.Money.Value = game.Players.(PLAYERNAME).leaderstats.Money.Value + 15000
                                            script.Parent.Parent:Destroy()
                                    end)
                                end             
    end)

1 answer

Log in to vote
0
Answered by
Elixcore 1337 Moderation Voter
4 years ago
Edited 4 years ago

Hey there, ClickDetectors returns a parameter called 'playerWhoClicked', It is the player object that has clicked the detector.

To use it properly here's an example:

partFolder.Enable.MainDetector.MouseClick:Connect(function(player) -- giving the player parameter a name, in this case player
    local playerName = player.Name -- accessing the player's Name. 
end)
0
so this gives me the name and how exactly would i be able to plug that into the script towards the bottom? N33H 19 — 4y
0
at the bottom instead of doing "game.Players.(PLAYERNAME)" you just do "player" Elixcore 1337 — 4y
0
this is the bottom script its telling me that the player isnt a valid member of players: if scriptFolder.CP3M.Value == 15000 then partFolder.Enable.SecondaryDetector.MouseClick:Connect(function(player) -- giving the player parameter a name, in this case player local playerName = player.Name game.Players.players.leaderstats.Money.Value = game.Players.player.leaderst N33H 19 — 4y
0
i told you, you dont need to do game.Players.player, you just need to do 'player' Elixcore 1337 — 4y
View all comments (3 more)
0
player.leaderstats.Money.Value = player.leaderstats.Money.Value + 15000 Elixcore 1337 — 4y
0
Ok so i re checked what u said, and i was being stupid and put it in the .players, i fixed it, thanks alot for helping me ive been stuck on this for a few hours! I can finally move on to other things in the game now. N33H 19 — 4y
0
Awesome, good luck on developing the game Elixcore 1337 — 4y
Ad

Answer this question