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

Ways of getting LocalPlayer in a cloned Server-Side Script?

Asked by 6 years ago

So I need ways of getting LocalPlayer in a cloned Server-Side Script. I originally intended on using

game.Players.PlayerAdded:connect(function(player)

but because it's cloned, PlayerAdded doesnt seem to function correctly. Any other ways of getting the LocalPlayer on a server-side script?

For context, and if it helps:

game.Players.PlayerAdded:connect(function(player)
script.Parent.Touched:connect(function(hit)
    if hit.Parent.Name == "Pickaxe" then
        player.Backpack.Copper.Value = player.Backpack.Copper.Value + 1
        script.Parent:Destroy()
    end
end)
end)

Any help is much appreciated as always.

0
ServerScripts aren't associated to a Client (player) in any way as they work on the Server. Can you tell me a bit about why you're cloning a ServerScript and I might be able to point you in the right direction Pejorem 164 — 6y
0
So it's a mining game, and there's a randomizer picker script that clones a certain ore if it is chosen. The above script is in all the ores. 360noscopehamcob 20 — 6y
0
You can't. The script doesn't know what player you want. It does not read your mind. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by
Pejorem 164
6 years ago
Edited 6 years ago

given the comments on your post you'd probably be better off accessing the player via the character

script.Parent.Touched:Connect(function(hit)
    if hit.Parent.Name == "Pickaxe" then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
        if plr then
            plr.Backpack.Copper.Value = player.Backpack.Copper.Value + 1
            script.Parent:Destroy()
        end
    end
end)

there's about a million things wrong with the framework of this that I can't be bothered to go into but learning things one thing at a time is probably better anyway aha.

0
Might also be worth putting a debounce on this as Destroy() might not work immediately Pejorem 164 — 6y
0
I've got a debounce set up and it's still taking over 5 hits from the pickaxe to destroy it on occasion, could I have help with this? 360noscopehamcob 20 — 6y
0
Put the debounce with the if hit.Parent.Name == "Pickaxe" bit. Add me on Discord if you've got further questions. Instance.new("Life", Noob)#3135 is my Discord handle. Pejorem 164 — 6y
Ad

Answer this question