#Hello i have a question about the roblox Creator hub and its scripts.

1 messages · Page 1 of 1 (latest)

exotic peak
#

I recently started trying out scripting and i wanted to learn it. Im using to learn the roblox creator hub and some side info that i write for myself (like a cheatsheet)
But i noticed that one of the scripts in the creator hub in coding Fundamentals doesnt work like they say it should. I wanted to ask how to fix that skript or if its entirely broken
Its supposed to make something like a coin collect system. Like if a player touches that colored block the get +50 points. But the skript doesnt work and now i am here and wanted to ask.

#

Heres the script:
local pointPart = script.Parent
--local storage = game:GetService("ServerStorage")

-- Gives some points
local blue = Color3.fromRGB(0, 0, 255)
-- Gives more points
local green = Color3.fromRGB(0, 255, 0)
-- Makes players lose points
local red = Color3.fromRGB(255, 0, 0)

-- gold given to players
local smallPoints = 10
local largePoints = 50
local losePoints = 100

local Players = game:GetService("Players")

local function givePoints(player)
local currentColor = pointPart.Color

local playerStats = player:WaitForChild("leaderstats")
local playerPoints = playerStats:WaitForChild("Points")

-- Gives player gold based on the color of the part
if currentColor == blue then
    playerPoints.Value += smallPoints
elseif currentColor == green then
    playerPoints.Value += largePoints
else
    playerPoints.Value -= losePoints
end

-- Destroy the part, wait a second, and then destroy the particle
pointPart:Destroy()

-- Creates a sparkles effect and destroys it
local playerCharacter = player.Character
local particle = Instance.new("ParticleEmitter")
particle.Color = ColorSequence.new(currentColor)
particle.Parent = playerCharacter:WaitForChild("Head")
task.wait(1)
particle:Destroy()

end

local function partTouched(otherPart)
local player = Players:GetPlayerFromCharacter(otherPart.Parent)

if player then
    givePoints(player)
end

end

pointPart.Touched:Connect(partTouched)

-- Changes the color of the part based on variables. Needs to be at bottom of script.
while true do
pointPart.Color = blue
task.wait(4)
pointPart.Color = green
task.wait(3)
pointPart.Color = red
task.wait(2)
end

dull quiver
#
local pointPart = script.Parent
--local storage = game:GetService("ServerStorage")

-- Gives some points
local blue = Color3.fromRGB(0, 0, 255)
-- Gives more points
local green = Color3.fromRGB(0, 255, 0)
-- Makes players lose points
local red = Color3.fromRGB(255, 0, 0)

-- gold given to players
local smallPoints = 10
local largePoints = 50
local losePoints = 100

local Players = game:GetService("Players")

local function givePoints(player)
    local currentColor = pointPart.Color

    local playerStats = player:WaitForChild("leaderstats")
    local playerPoints = playerStats:WaitForChild("Points")

    -- Gives player gold based on the color of the part
    if currentColor == blue then
        playerPoints.Value += smallPoints
    elseif currentColor == green then
        playerPoints.Value += largePoints
    else
        playerPoints.Value -= losePoints
    end

    -- Destroy the part, wait a second, and then destroy the particle
    pointPart:Destroy()

    -- Creates a sparkles effect and destroys it
    local playerCharacter = player.Character
    local particle = Instance.new("ParticleEmitter")
    particle.Color = ColorSequence.new(currentColor)
    particle.Parent = playerCharacter:WaitForChild("Head")
    task.wait(1)
    particle:Destroy()
end

local function partTouched(otherPart)
    local player = Players:GetPlayerFromCharacter(otherPart.Parent)

    if player then
        givePoints(player)
    end
end

pointPart.Touched:Connect(partTouched)

-- Changes the color of the part based on variables. Needs to be at bottom of script.
while true do
    pointPart.Color = blue
    task.wait(4)
    pointPart.Color = green
    task.wait(3)
    pointPart.Color = red
    task.wait(2)
end 
#

how does it not work?