Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I make my remote functions work here?

So I have a tool, and I want it to add on to the Players value each use

Code for tool (Local Script):

local Tool = script.Parent;
enabled = true




function onActivated()
	if not enabled  then
		return
	end

	enabled = false
	--Call Function--
	
	local fatFunc = game.ReplicatedStorage:WaitForChild("hyh")


	local addfat = fatFunc:InvokeClient(0.01)
	game.Players.LocalPlayer.Data.Fatness.Value = game.Players.LocalPlayer.Data.Fatness.Value + addfat

	
	
--[[		
		local eat = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Parent.Animation)
		local current = eat
		current:Play()
--]]		
		wait(4.20)


	enabled = true

	end

script.Parent.Activated:connect(onActivated)

Server Script:

local fatFunc = game.ReplicatedStorage:WaitForChild("hyh")


function fatFunc.OnClientInvoke(value)
		local addfat = 0.01			
		return addfat		
end

Any help is appreciated and thanks in advanced :)

1 answer

With remote functions, you want to use InvokeServer to call the server from a local script, and OnServerInvoke on the server to listen for that invocation. In your case though, you probably want to be using a remote event, and change the players fatness value on the server, like so:

Here hyh is a RemoteEvent

-- In a local script
local fatFunc = game.ReplicatedStorage:WaitForChild("hyh")
fatFunc:FireServer()
-- In a server script
local fatFunc = game.ReplicatedStorage:WaitForChild("hyh")
fatFunc.OnServerEvent:connect(function(player)
	player.Data.Fatness.Value = player.Data.Fatness.Value + 0.01
end)

1 comment

0

Thank you so much I had been stuck on this for so long!

This discussion is preserved as it was. New answers, comments, and votes are closed.