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

How to call a function from server to client? [UNANSWERED]

Asked by
IXLKIDDO 110
9 years ago

I am trying to create a chat command (one you can type in-game and activate the function) to either lock someone in first person or allow them to zoom out once again. My problem is getting the command to send it to the players. So far I have this in the localscript:

function game.Workspace.OnClientInvoke(FirstPerson)
    game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
end

function game.Workspace.OnClientInvoke(ThirdPerson)
    game:GetService('Players').LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
end

And this in the Server Script:

function onCommand(message, player)
    if message:sub(1, 12) == ":firstperson" and TrueAdmin[player.Name] then
    local CameraMode = Instance.new("Camera Mode")
    CameraMode.Parent = game.Workspace
    CameraMode.Name = "First Person"
    function CameraMode(player)
        local success, result = pcall(function() return CameraMode:InvokeClient(player) end)
            if success then
                print(result)
            else
                print("Not able to change Camera Mode")
            end
        end
    end
    if message:sub(1, 12) == ":thirdperson" and TrueAdmin[player.Name] then
    local CameraMode = Instance.new("Camera Mode")
    CameraMode.Parent = game.Workspace
    CameraMode.Name = "First Person"
    function CameraMode(player)
        local success, result = pcall(function() return CameraMode:InvokeClient(player) end)
            if success then
                print(result)
            else
            print("Not able to change Camera Mode")
            end
        end
    end
end
-- Chat commands are working. I have already got that and these are in a function.

EDIT: Edited on mobile. So pardon the missed tabs.

Thanks a lot for helping me out. I realize that I may have been asking quite a few questions, but thank you so much.

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem is that you're using ServerScriptStorage for storing something that you want to use to manipulate the client.

Look closer: ServerScriptService

See why it's not working now?

Store your RemoteFunction in ReplicatedStorage and then you should be set(:

0
Do you mean my localscript, or my regular script? IXLKIDDO 110 — 9y
0
You said your localscript was in ServerStorage. Goulstem 8144 — 9y
Ad

Answer this question