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

How to make a part in workspace award points under the player when touched?

Asked by 6 years ago

I have a part under workspace called "Coin" I want to be able to collect this coin and when collected it updates the player points that i have stored under the player as well as the gui I have showing the player those points. My main script is under ServerScriptService. My points system does work when a player joins and plays a match they get the points and the gui updates with the new point value. There is no error output. Does there need to be a script under the coin itself? This is what I have so far under my main game script:

local Coin
game.workspace.Coin.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") ~=nil then
    if Coin == true then
        Coin = false
        game.workspace.Coin.Transparency = 1
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
for _,Player in pairs(game.Players:GetPlayers()) do
    if Player:FindFirstChild("Points") then
        awardpoints(player, 10)
             end
        end
    end
end

end)

0
Where is 'awardpoints' function? .-. luadotorg 194 — 6y
0
The function is at the top of the script and works fine. My main question is how can i make the coin count towards the points when touched in game if the points are under player. Zeustice 41 — 6y
0
Why are you using in pairs if you want it to award just the player who touches it? PyccknnXakep 1225 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I don't understand why you're using in pairs when you are just trying to award it to the player who touches it.

script.Parent.Coin.Touched:Connect(function(hit) --wherever the part is
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    local points = player:WaitForChild("leaderstats").Points --index where the leaderstat is stored
    points.Value = points.Value + 10 --award 10 points to the player
end)

Note: I am writing this from scratch so if it doesn't work please let me now, if it did however please accept my answer if this helped!

0
Please ignore the in pairs my bad I was tired at the time of writing this. Thank you for your response. My main issue is I have the points stored under the player it is private and not part of the leaderstat. I have a GUI the reflect the points value for each player instead. The coin is sitting in workspace and i have a main script for the game under ServerScriptService. I have a defined functi Zeustice 41 — 6y
0
just change the variable points to where the stat is located thats all you need to do PyccknnXakep 1225 — 6y
0
Alrighty, and put this script under the coin itself or within the main game script? Zeustice 41 — 6y
0
Under the coin itself. PyccknnXakep 1225 — 6y
0
It worked! Thank you for the help. Zeustice 41 — 6y
Ad

Answer this question