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

How do you get a player from a server script with no events?

Asked by 3 years ago

Hey, so I'm trying to make a hitbox thing damage IDK what to call it but anyways the script is meant to do this :D

If a player clicks a part 5 times they make the part get deleted and they receive currency/Money

But here's the problem how do I award a player with Money?

local HitValue = 0

script.Parent.ClickDetector.MouseClick:Connect(function()

    HitValue = HitValue + 1

    print(HitValue)
end)

while HitValue < 10 do
    wait()
    if HitValue == 5 then
        script.Parent.Parent.TestingWoodPart:Destroy()
    end
end

2 answers

Log in to vote
0
Answered by 3 years ago
local HitValue = 0
local player

script.Parent.ClickDetector.MouseClick:Connect(function(detected_player)

    HitValue = HitValue + 1
    print(HitValue)
    player = detected_player

end)

while HitValue < 10 do
    wait()
    if HitValue == 5 then
        script.Parent.Parent.TestingWoodPart:Destroy()
    player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 --you can modify "Money" with the correct name or the value
    end
end
Ad
Log in to vote
0
Answered by 3 years ago

https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseClick

workspace.Baseplate.ClickDetector.MouseClick:Connect(function(player) -- Click detectors have a parameter for PlayerWhoClicked. When using function(player) you are able to get the player.
    print(player.Name)
end)
0
Thanks, I know have a better understanding of this :D johnoscarbhv1 137 — 3y

Answer this question