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

How can I invoke a remote function from a part in workspace? Or do I even need to?

Asked by 5 years ago

I have a simple circle part in the workspace, and I want it so whenever the player walks into it, it invokes my "SellPtns" remote function. However, I'm getting an error saying it can only be fired client side. This remote function basically just sells whatever is in the player's inventory in exchange for one coin, and both of those values live in a datastore.

So does this script in workspace run on server side? I'm not sure if I should be changing datastore values without using a remote of some kind, in fear of it causing exploit issues. But if it's running on the server, the client shouldn't be able to access the script anyway, right?

local Part = script.Parent

--Get remote function from replicated storage
local replicatedStorage = game:GetService("ReplicatedStorage")

Part.Touched:Connect(function(HIT)
    local H = HIT.Parent:FindFirstChild("Humanoid") 
    if H then
        local player = game.Players:GetPlayerFromCharacter(HIT.Parent)  
if player then
    local success
    success = replicatedStorage.RemoteFunctions.SellPtns:InvokeServer()

    if success then
        print ("Potions sold successfully")
    end 
end
end
end)
0
You can't call "InvokeServer" on a server script. Unhumanly 152 — 5y

1 answer

Log in to vote
0
Answered by
karlo_tr10 1233 Moderation Voter
5 years ago

As you are using server script you don't need to call remotes. Remotes are used so a client can change something on a server or so the server can access some stuff that only client can. You shouldn't be worried about exploiters.

0
Okay makes sense thank you! exciteddolphin 9 — 5y
Ad

Answer this question