Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

This is the current script.

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

1 comment

0

Please format your code using a codeblock. (The Lua button).

1 answer

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!

3 comments

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.

0

He never added a debounce so try that.

0

@SpaghettiM0nster, LocalPlayer would work fine in a local script.

This discussion is preserved as it was. New answers, comments, and votes are closed.