Hey! To handle the coins in my game, I wrote (with some help) this script. However it does not function. No errors are outputed. I am not sure what the problem in the script is.
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local CoinFol = game.Workspace.Coins
local r = math.rad
function RotateCoin()
for _, coin in pairs(CoinFol:GetChildren()) do
coroutine.wrap(function()
while task.wait() do
coin.CFrame *= CFrame.Angles(r(0), r(1), r(0))
end
end)
end
end
function CoinTouched(Coin,hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local char = hit.Parent
local coinV = require(game.ServerScriptService.FastGet)(player.UserId,"Coin")
if Coin:WaitForChild("Particle",1) then
coinV.Value += 10
else
coinV.Value += 2
end
local XPV = require(game.ServerScriptService.FastGet)(player.UserId,"Xp")
XPV.Value += 20
Coin:Destroy()
end
end
function ConnectCoins()
for _, coin in pairs(CoinFol) do
coin.Touched:Connect(function(p2) CoinTouched(coin,p2) end)
end
end
function LoopC()
while true do
wait(0.5)
RotateCoin()
end
end
coroutine.wrap(LoopC)
This is that module script, it is not the cause of the Issue.
local module = function (playerID,aspect)
local PFol = game.ReplicatedStorage.PlayerData[playerID]
if PFol then
local varS = PFol[aspect]
if varS then
return varS
end
end
end
return module
local TweenService = game:GetService("TweenService")
local Players = game:GetService("Players")
local CoinFol = game.Workspace.Coins
local r = math.rad
function RotateCoins()
coroutine.wrap(function()
while task.wait() do
for _, coin in pairs(CoinFol:GetChildren()) do
coin.CFrame *=CFrame.Angles(r(0), r(1), r(0))
end
end
function CoinTouched(Coin,hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
local char = hit.Parent
local coinV = require(game.ServerScriptService.FastGet)(player.UserId,"Coin")
if Coin:WaitForChild("Particle",1) then
coinV.Value += 10
else
coinV.Value += 2
end
local XPV = require(game.ServerScriptService.FastGet)(player.UserId,"Xp")
XPV.Value += 20
Coin:Destroy()
end
end
for _, coin in pairs(CoinFol) do
coin.Touched:Connect(function(p2)
CoinTouched(coin,p2)
end)
end
RotateCoins()
Привет, у тебя встречаются 3 проблемы:
Неправильное использование функций.
Ты забыл вызвать некоторые функции.
Неправильное использование циклов.
Я отредактировал код, но возможно что-то упустил. Если проблема останется, то пиши мне. Также, не забывай смотреть в Output.
If your module is working, then try changing the value inside of the module.
local module = function (playerID,aspect)
local PFol = game.ReplicatedStorage.PlayerData[playerID]
if PFol then
local varS = PFol[aspect]
if varS then
varS.Value += 10
--return varS
end
end
end
return module
I know, which is why as I said above to try changing the value of your item inside the module. You’re getting the item inside the module so change it there too.
I think you misunderstand the purpose of that ModuleScript. It is just to return the IntValue that contains the variable. Example: Coin, Xp or Token. Not to add only 10 to the value, like what you added to it. If all the variables (Token,Coin,Xp,ect.) only needed to be added by 10, then your idea would work. ModuleScripts are for multiple scripts. I suggest you look more into the function of Module Scripts.
The coins in CoinFol spawn in overtime, so I had to do a while true do in there. But that excelirated the Coins to rotate very quickly and it caused massive XP and COIN dupes.
Just to explain it further, the purpose of the ModuleScript is to go through that player file and return the IntValues, whom values could then be changed in the Script
It just returns the IntValue objects, whom Values are changed by the ServerScript requesting it. Which is then saved into the Player’s Datastore when they leave and loads when the player joins.