I'm trying to make a "coin/token" script and when you touch it you are supposed to pick it up but right now it all works in studio but not online.
On line 84, I'm calling the RemoteFunction
and the arguments I'm sending thru to the server is my Token I touched and want to pick up.
On studio it works to send thru the token but online when I try to print the argument I'm receiving on the server it just prints nil but in studio it prints the token I'm sending thru.
On the client, before I'm sending thru the token I tried to print the token and it prints.
The question I'm asking why is this only working on studio and not online?
I'm guessing the problem is starting from line 70 to end end of that function.
Modulescript on the client:
local module = {} module.__index = module local player = game.Players.LocalPlayer local TokenTypes = require(game.ReplicatedStorage.TokenTypes) local Notify = require(script.Parent.Notify) local CoinsDump = workspace.CoinsDump function module:NewToken(Type, NPC) local self = { Type = Type, NPC = NPC, } setmetatable(self, module) self:NewModel() end function module:NewModel() local Tokens = game.ReplicatedStorage.Tokens local Token = Tokens[self.Type]:Clone() Token.Parent = CoinsDump Token.PrimaryPart.CFrame = self.NPC.PrimaryPart.CFrame * CFrame.Angles(math.rad(90), 0, 0) + Vector3.new(math.random(1, 2), math.random(1, 2), math.random(1, 2)) local BillboardGui = Token.PrimaryPart:FindFirstChild("BillboardGui") local Time = BillboardGui:FindFirstChild("Time") local Rot = 90 local TimeValue = 20 local function TweenRotation() if not Token or not Token.PrimaryPart then return end local TweenService = game:GetService("TweenService") local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Linear) local Tween = TweenService:Create(Token.PrimaryPart, TweenInfo, {CFrame = Token.PrimaryPart.CFrame * CFrame.Angles(0, 0, math.rad(Rot))}) Tween:Play() Tween.Completed:Wait() TweenRotation() end spawn(function() TweenRotation() end) spawn(function() repeat wait(1) TimeValue = TimeValue - 1 until TimeValue == 0 Token:Destroy() end) spawn(function() Time.Text = "00:" .. TimeValue repeat wait(1) if TimeValue >= 10 then Time.Text = "00:" .. TimeValue else Time.Text = "00:0" .. TimeValue end until TimeValue == 0 end) local debounce = false Token.PrimaryPart.Touched:Connect(function(Hit) if Hit:IsA("BasePart") then local player = game.Players:GetPlayerFromCharacter(Hit.Parent) for i,v in pairs(TokenTypes.Types) do if v["Type"] == Token.Name then local Rewards = v["Rewards"] local Category = Rewards["Category"] local Amount = Rewards["Amount"] if not debounce then debounce = true print(Token) game.ReplicatedStorage.Events.GrabToken:InvokeServer(Token) Notify.NewAlert(player, Category, Amount) Token:Destroy() wait(0.01) debounce = false end end end end end) end return module
Serverscript:
function Events.GrabToken.OnServerInvoke(player, Token) print(player, Token) if not player or not Token then return end for i,v in pairs(TokenTypes.Types) do if v["Type"] == Token.Name then local Rewards = v["Rewards"] local Category = Rewards["Category"] local Amount = Rewards["Amount"] DataStoreHandler.AddToStat(player, player, Category, Amount) ServerAchievements.AddProgress(player, player, "Tokens") ClientUpdate:InvokeClient(player, player) UpdateBackpack.Update(player, player) end end end
Hard to tell what you're sending over to the server since it's a bit cut off, I will assume you are sending a Token
.
The reason that it comes up as nil is because you can't send objects from the client to server or server to client. You can only send datatypes such as...
Numbers, Tables, Strings, Booleans, CFrames, Vectors, ect...
So in order to send your Token
you will need to convert it down to sendable datatypes and send that to the server.
Also note: It looks like you are trying to save the data too - it may be a sort of local cache saving module you made, but if it is actually saving to a Datastore, then the same rules apply for that (even more restricted though).
In Datastores your datatypes have to be even more primitive - you can't use Vectors or CFrames, especially not objects.
The wiki explains this here:
https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events#Non-replicated_Instances