{Closed} Fire Server Can only be called from the client

Basically, by touching the coin, I want to increase a value, but to start off, I tohught about doing the print() just do see if it would work, but when I touched the coin, the message does print but I get this warning: https://gyazo.com/98a81db85cd0899303fafc68658fb14d

Do I maybe need a remote function instead of event?

If you need more details just tell me :slight_smile:

2 Likes

I believe that is self explanatory. You cannot call RemoteEvent::FireServer from a server script. Remotes are meant for client <-> server communication.

2 Likes

do a local script in starter pack or something with this

local coin = workspace.Coin

coin.Touched:Connect(function()
      remoteevent:FireServer()
end

server script

remoteevent.OnServerEvent:Connect(function()
      value.Value = value.Value + 1
end
2 Likes

I don’t think a local script will know whether the character has touched the coin.

1 Like

you can detect clicks in local scripts

But you used a touched event not a MouseButtonClick.

I know but, let me just try in studio

it did work, I tried it in studio

1 Like

Because the thing is that the player can’t touch a coin the character can.

1 Like

it works, i just tried it in studio, also this would require the player but in my code i only am giving a example of how to raise a value, he could easily transfer the player that touched it to the server and have the server raise their leaderstats

2 Likes

I disagree, You shouldn’t even need a remote for this, use a single script in serverscriptservice. Where these coins are spawned (of cores I don’t know your system, but you need one) you should do this:

local Coin = Instance.new("Part");

Coin.Parent = workspace;
Coin.Touched:connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        --// hit.Parent is your character, just give it a value here.
        Coin:Destroy() --// Removing coin after gaining it.
    end
end)
1 Like

but wont it be easily exploitable?

Having it as a localscript will make it vulnerable to exploits.

An exploiter could do something like this and abuse that system:

while true do
    wait()
    remoteevent:FireServer();
end

In record it’s more secure to have this all within a server script.
@ekuz0diaaI I get that, I just recommend a better solution.

Is my solution exploitable? Yes, but way less effective as they’d have to teleport to each coin. If you add a debounce to it you’ll be 100% to go with the exploit problem.

1 Like

yeah, your way is more efficient but i was answering him with the remoteevent thing and how he tried firing it from the server, thats why i used remote events.

You can just do it like this in a ServerScript. That way it wont be exploitable.

local coin = workspace.Coin

coin.Touched:Connect(function(hit)
    value.Value = value.Value + 1
end

Well, he edited the script, before it was a server script just like yours

edit:saw you removed that part.