So what I am trying to achieve is where when a player touches a part, that part changes the text on a on-screen gui. For example, if I had a textlabel with the number, “1” on my screen, the part would change that number to “2” and so on and so forth. I tried to create this function as a remote function event, and so when the player touches the part, it fires a event which leads to a script inside StarterGui. But for some reason, there is a error that says, “FireClient:player argument must be a player object.”
Here is my scripts:
local player = game.Players.LocalPlayer
local ObjectivesGui = game.StarterGui.ObjectivesGui
script.Parent.Touched:Connect(function(player)
game.ReplicatedStorage.Completed1:FireClient(player)
end)
You do not automatically get the player when a part is touched by a player. This script should work. (this is the script for the script inside the Complete1
part.)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:IsA("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent);
game.ReplicatedStorage.Completed1:FireClient(player);
end
end)
1 Like
You should try:
- - in block Script 1:
local plr = game.Players.LocalPlayers or game:GetService("Players").LocalPlayer or game.Players.PlayerAdded
script.Parent.Touched:Connect(function()
game.ReplicatedStorage.Completed1:FireServer();
end)
Just change the KeyEvent to
KeyEvent.OnServerEvent:Connect(function()
1 Like
@YourBossyLord There is no such thing as game.Players.LocalPlayers
, and you cannot get a localplayer from a regular script inside of workspace
. Not just that, but you cannot use OnServerEvent
inside of localscripts, OnServerEvent
is supposed to be used in regular scripts usually in the server. Not just that, Why would you be doing :FireServer()
inside of a regular script…? You would use bindables to communicate from server → server and use :Fire()
for them. To communicate to the client from a regular script, you can use :FireClient()
then OnClientEvent
in the localscript.
1 Like
You can’t get the player with game.Players.LocalPlayer in a server script.