Trouble Sending a String through Remote Events

Hello!

I’m having this issue where I can’t send a string though a remote event.

I don’t mess around with remote events a lot so its probably something dumb :stuck_out_tongue:

The Error is as follows

  12:23:44.798  Unable to assign property Text. string expected, got nil  -  Client - LocalScript:7
  12:23:44.798  Stack Begin  -  Studio
  12:23:44.798  Script 'Players.omotashi.PlayerGui.Objective.LocalScript', Line 7  -  Studio - LocalScript:7
  12:23:44.798  Stack End  -  Studio

The code is asfollows

Client Script (handles the request)

local OBJEvent = game.ReplicatedStorage.Events:WaitForChild("NewObjective")
local Frame = script.Parent.Main
local TextBox = Frame.TextLabel

OBJEvent.OnClientEvent:Connect(function(player, newobj)
	
	TextBox.Text = newobj
	
	Frame:TweenPosition(UDim2.new(0.749, 0,0.425, 0))
	
	wait(2)
	
	Frame:TweenPosition(UDim2.new(1.1, 0,0.425, 0))
	
end)

Server/Touched Event

script.Parent.Touched:Connect(function(hit)
	local character = hit.Parent
	local h = character:WaitForChild("Humanoid")
	local player = game.Players:GetPlayerFromCharacter(character)
	if h ~= nil then
		local newobj = "Go Somewhere"
		game.ReplicatedStorage.Events.NewObjective:FireClient(player, newobj)
	end
end)

Any help is wonderful!

2 Likes

The first argument passed in OnClientEvent is not the player as you are already firing the remote event to the specific client. Remove the player variable in the local script.

Here is what your local script should look like:

local OBJEvent = game.ReplicatedStorage.Events:WaitForChild("NewObjective")
local Frame = script.Parent.Main
local TextBox = Frame.TextLabel

OBJEvent.OnClientEvent:Connect(function(newobj)
	
	TextBox.Text = newobj
	
	Frame:TweenPosition(UDim2.new(0.749, 0,0.425, 0))
	
	wait(2)
	
	Frame:TweenPosition(UDim2.new(1.1, 0,0.425, 0))
	
end)
1 Like

Thank you!!! It worked. Thank you so much!!

1 Like

You are welcome, happy to help! You may mark my post as a solution if other people face the same issue, so that they can find this topic.