Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make my remote functions work here?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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)
0
Thank you so much I had been stuck on this for so long! VeryDarkDev 47 — 6y
Ad

Answer this question