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

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

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)

1 comment

0

You can't call "InvokeServer" on a server script.

1 answer

✓ Accepted answer

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.

1 comment

0

Okay makes sense thank you!

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