This is the current script.
function onTouched() game.Players.Player.Coins.Value = 1 end script.Parent.Touched:connect (onTouched)
This is the current script.
function onTouched() game.Players.Player.Coins.Value = 1 end script.Parent.Touched:connect (onTouched)
Hello,
Your script won't work for a few reasons:
Player isn't a valid Player. You need to use an actual player.
You're setting the Player's coins to 1 every time.
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!
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.
He never added a debounce so try that.
@SpaghettiM0nster, LocalPlayer would work fine in a local script.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Please format your code using a codeblock. (The Lua button).