There are a few errors I noticed here.
- You are not using the required module to call the functions.
- You cannot concatenate strings and values using +
- You are trying to alter StarterGui which will have no affect on their screen.
- You are not using the module to contain the function (I'll explain this one in detail)
Error 1
It's mainly not working because you have to use the required module to get the functions that are returned from it.
So, line 23 you are not using req, the required module.
Line 23 should look like this.
req.UpdateHempCount(collider, 1)
This will call the desired function from the module script with the required arguments.
Error 2
- Is for adding values together. It's not for concatenating strings and values.
To concatenate strings and values you would use ..
So, In your module script on Line 4 you should change + to ..
Line 4 should look like this.
game.StarterGui.ScreenGui.TextLabel.text = "HEMP: "..player.leaderstats.Hemp.Value + value
Error 3
Anything being changed in StarterGui will have no affect on the players in the game. You would want to change the PlayerGui located inside of the player.
You would do player.PlayerGui.ScreenGui.TextLabel.Text
So, line 4 would look like this (ModuleScript)
player.PlayerGui.ScreenGui.TextLabel.Text = "HEMP: " + player.leaderstats.Hemp.Value + value
Error 4
You have to use the module to hold functions inside of the return method.
Without this, it'll run the function, but not for the player. Also, don't use Local for functions inside of the ModuleScript.
So, your ModuleScript should look like this.
local module = {}
function module:UpdateHempCount(player, value)
game.StarterGui.ScreenGui.TextLabel.text = "HEMP: " + player.leaderstats.Hemp.Value + value
end
return module
You can use . or : - It doesn't matter that much.
These are the final scripts.
ServerScript
local hempModule = require(game:GetService('ReplicatedStorage').updateHemp)
local interactable = true
local function HempRegen()
script.Parent.Transparency = 1
wait(10)
script.Parent.Transparency = 0
interactable = true
end
local function onTouch(player)
if interactable then
local p = player.Parent.Name
print(p)
local collider = game.Players:GetPlayerFromCharacter(player.Parent)
collider.leaderstats.Hemp.Value = collider.leaderstats.Hemp.Value + 1
interactable = false
hempModule:UpdateHempCount(collider, 1)
HempRegen()
end
end
script.Parent.Touched:Connect(onTouch)
Module Script
local hempModule = {}
function hempModule:UpdateHempCount(player, value)
player.PlayerGui.ScreenGui.TextLabel.Text = "HEMP: "..player.leaderstats.Hemp.Value + value
end
return hempModule
Hope this helped! If this worked, let me know by selecting this as an answer!
2 comments
Include the function in the module table and then call the function by doing req.UpdateHempCount().
You never used req.UpdateHempCount (whatever Hemp is). To call a function from a module script use moduleScriptName.WhateverFunction.