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

Why won't this point giving script work? I use it for a coin system.

Asked by 6 years ago

This is the current script.

function onTouched() game.Players.Player.Coins.Value = 1 end script.Parent.Touched:connect (onTouched)

0
Please format your code using a codeblock. (The Lua button). Eqicness 255 — 6y

1 answer

Log in to vote
0
Answered by
Eqicness 255 Moderation Voter
6 years ago
Edited 6 years ago

Hello,

Your script won't work for a few reasons:

  1. Player isn't a valid Player. You need to use an actual player.

  2. You're setting the Player's coins to 1 every time.

  3. To get a player from the object that touched the brick, you can use the Player's Service :GetPlayerFromCharacter function. Here's how:

local brick = script.Parent
local players = game:GetService("Players")

brick.Touched:Connect(function(touchedPart) -- Detect when the brick is touched and what part touched it.
    if players:GetPlayerFromCharacter(touchedPart.Parent) then  -- Check if the touched part's Parent is a Player's Character.
        local plr = players:GetPlayerFromCharacter(touchedPart.Parent)  -- Define the player
            plr.Coins.Value = plr.Coins.Value + 1   -- Add 1 to the player's coins.
    end
end)

Have fun coding!

0
Hey i realized the second point too, but why would LocalPlayer not work. I've been using that in testing, and it works, but on a real server it does not. SpaghettiM0nster 0 — 6y
0
He never added a debounce so try that. nap516 87 — 6y
0
@SpaghettiM0nster, LocalPlayer would work fine in a local script. Eqicness 255 — 6y
Ad

Answer this question