How to send a module's function data to client from server?

So, I am trying to send a module’s function to client

this is the module I am trying to send

in the serverScripts.

and this is the part I am trying to send
I want to send data of Rewards.Coins to client using FireClient


and lastly the client script which should recieve the data from server

-Rewards Module script

local ServerScriptService = game:GetService("ServerScriptService")
local StatsModule = require(ServerScriptService:WaitForChild("Stats"))
local Rewards = {}
function Rewards.strength(player, Amounth, UseMultiplier)
	UseMultiplier = if UseMultiplier ~= nil then UseMultiplier else true
	local Rankmultiplier = if UseMultiplier == true then StatsModule.StrengthMultiplier(player) else 1
	player.leaderstats.Strength.Value +=  Amounth * Rankmultiplier 
	print(Amounth,Rankmultiplier,Amounth*Rankmultiplier)
end
function Rewards.Coins(player, Amounth, UseMultiplier)
	UseMultiplier = if UseMultiplier ~= nil then UseMultiplier else true
	local Rankmultiplier = if UseMultiplier == true then StatsModule.CoinMultiplier(player) else 1
	player.leaderstats.Coins.Value +=  Amounth * Rankmultiplier 
end
return Rewards

– script to send the data

ScriptableFolder.Sell.Touched:Connect(function(hit)
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local Strength = player.leaderstats.Strength.Value

 	   if Strength >0 then
		Rewards.Coins(player,Strength,true)
			player.leaderstats.Strength.Value = 0
remotes.SellEventTextRemotes:FireClient(player)
		end
		end
end)

-Local script

-- remotes.SellEventTextRemotes.OnClientEvent:Connect(function(Rewards.Coins)
	--warn("Client got data from activating a tool:", Stat)
	local TweenService = game:GetService("TweenService")

	local SellCoinsClone1 = SellCoins1:Clone()
	local SellCoinsClone2 = SellCoins2:Clone()
	local SellCoinsClone3 = SellCoins3:Clone()
	local SellCoinsClone4 = SellCoins4:Clone()
	local SellCoinsClone5 = SellCoins5:Clone()

	local Info = TweenInfo.new(3)
	local Tween = game:GetService("TweenService"):Create(SellCoins1,Info,{TextTransparency=1})

	Tween:Play()
	SellCoins1.Parent= script.Parent
	SellCoins1.Visible = true
	SellCoins1.Text = "+"..tostring()
	SellCoins1.Position = GetRandomPosition()
	local newPos = SellCoins1.Position + UDim2.fromScale(0,-0.4)
	SellCoins1:TweenPosition(newPos,"In","Quad",1,false)
	SellCoins1.Rotation = math.random(-15,0)
	print("welp")
	wait(3)
	SellCoins1:Destroy()
end)

Yeah, I still need the answer welp 30 thing

I’m assuming that you’re trying to pass a function into a remote event. In that case, it’s impossible.

1 Like

well, Rewards.Coins Sends a number I want to pass that number into a remote event but I guess it is impossible?

Oh I thought you’re passing in the actual function. But even then, your Rewards.Coins function doesn’t even return any number. I guess you could first change the Rewards.Coins function like this:

function Rewards.Coins(player, Amounth, UseMultiplier)
	UseMultiplier = if UseMultiplier ~= nil then UseMultiplier else true
	local Rankmultiplier = if UseMultiplier == true then StatsModule.CoinMultiplier(player) else 1
	local reward = Amounth * Rankmultiplier
	player.leaderstats.Coins.Value += reward
	return reward
end

Then in your server script, use this:

ScriptableFolder.Sell.Touched:Connect(function(hit)
	local player = players:GetPlayerFromCharacter(hit.Parent)
	if player then
		local Strength = player.leaderstats.Strength.Value
		if Strength > 0 then
			local amount = Rewards.Coins(player,Strength,true)
			player.leaderstats.Strength.Value = 0
remotes.SellEventTextRemotes:FireClient(player, amount)
		end
	end
end)

And for your client script do this:

 remotes.SellEventTextRemotes.OnClientEvent:Connect(function(coins)
	--warn("Client got data from activating a tool:", Stat)
	local TweenService = game:GetService("TweenService")

	local SellCoinsClone1 = SellCoins1:Clone()
	local SellCoinsClone2 = SellCoins2:Clone()
	local SellCoinsClone3 = SellCoins3:Clone()
	local SellCoinsClone4 = SellCoins4:Clone()
	local SellCoinsClone5 = SellCoins5:Clone()

	local Info = TweenInfo.new(3)
	local Tween = game:GetService("TweenService"):Create(SellCoins1,Info,{TextTransparency=1})

	Tween:Play()
	SellCoins1.Parent= script.Parent
	SellCoins1.Visible = true
	SellCoins1.Text = "+"..tostring(coins)
	SellCoins1.Position = GetRandomPosition()
	local newPos = SellCoins1.Position + UDim2.fromScale(0,-0.4)
	SellCoins1:TweenPosition(newPos,"In","Quad",1,false)
	SellCoins1.Rotation = math.random(-15,0)
	print("welp")
	wait(3)
	SellCoins1:Destroy()
end)
1 Like

It worked! Thank you very much

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.