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

ModuleScript Adding Points Not Working?

Asked by 5 years ago

Everything seems to work, it just won't change the value's number whenever a ball hits it.

ModuleScript:

local gamescript = {}

function gamescript.addscore(value)
    value = value + 1
end

return gamescript

Script:

local SSS = game:GetService("ServerScriptService")
local GameScript = require(SSS:WaitForChild("GameScript"))

local Values = workspace.Values
local Team1Value = Values:FindFirstChild("Team1")

local part = script.Parent
local debounce = true

part.Touched:Connect(function(hit)

    if hit.Name == "Ball" and debounce then
        debounce = false
        print("Ball Found")
        GameScript.addscore(Team1Value.Value)
        wait(1)
        debounce = true
    end

end)

Please help.

Thanks,

LukeGabrieI

1 answer

Log in to vote
1
Answered by
yHasteeD 1819 Moderation Voter
5 years ago
Edited 5 years ago

REMEMBER, NOT SEND .Value ONLY THE OBJECT! OR YOU GET ERROR ON EDIT!

Try to add .Value in ModuleScript

Example:

local a = {}

function a.add(v)
    v.Value = v.Value + 1
end

return a

and on your touch script not send Value only the IntValue(or NumberValue)

Here is fixed your script:

-- TOUCH --
local SSS = game:GetService("ServerScriptService")
local GameScript = require(SSS:WaitForChild("GameScript"))

local Values = workspace.Values
local Team1Value = Values:FindFirstChild("Team1")

local part = script.Parent
local debounce = true

part.Touched:Connect(function(hit)

    if hit.Name == "Ball" and debounce and Team1Value ~= nil then -- i added Team1Value ~= nil for no get errors on try to find Team1
        debounce = false
        print("Ball Found")
        GameScript.addscore(Team1Value) -- I only send the Object
        wait(1)
        debounce = true
    end

end)

------------------ SEPARATOR ------------------

-- MODULE SCRIPT --
local gamescript = {}

function gamescript.addscore(value)
    value.Value = value.Value + 1 -- Here i added .Value for change the value
end

return gamescript

Hope it helped :)

Ad

Answer this question