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

Why is my string not going through my RemoteEvent?

So, I made this script that once someone buys a Developer Product, it fires a remote event to the client that bought it. It will then tween down a UI that says thank you for your purchase.

I'm trying to make it say for example, if they bought 5000 cash, it would say thank you for purchasing 5000 cash. But its not working.

It just displays Nil on the UI

This is my client side code

--// Variables

local remote = game.ReplicatedStorage.BoughtProductMessage
local text = script.Parent.ProductName

remote.OnClientEvent:Connect(function(player, ProductName)
	print("Recived.")
	text.Text = tostring(ProductName)
	script.Parent.Parent:TweenPosition(UDim2.new(0.5, 0,0.5, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, false)
	wait(5)
	script.Parent.Parent:TweenPosition(UDim2.new(.5, 0,-0.2, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Quad, 1, false)
end)

This is PART of my server side code

if receipt.ProductId == FIVE_THOUSAND then
	if stats ~= nil then 
		stats.Value = stats.Value + 5000
		local bought = "5,000 Cash!"
		remote:FireClient(player, bought)
		print("Fired")
	end
end

2 comments

0

make a if statement to see if it goes to the right player

0

It would better if u shown the whole part code to see where you have gone wrong

2 answers

This won't work since the server is firing to the client, once the client gets the signal of the remote event fired, it ignores the player parameter

you did this:

remote.OnClientEvent:Connect(function(player, ProductName)

The player didn't receive the player argument, causing your text to say: "nil".

Do this instead:

remote.OnClientEvent:Connect(function(ProductName)

Simple fix, hope this helps.

Try and do something like this in the client script

remote.OnClientEvent:Connect(function(player, ProductName)
	if player.Name == game.Players.LocalPlayer.Name then
		--Code
	end
end)

And also I notice you already localised the text TextLabel but you are still using script.Parent.Parent:Tween when you could just simply do text:TweenPosition()

Here is an example of the client script

local remote = game.ReplicatedStorage.BoughtProductMessage
local text = script.Parent.ProductName

remote.OnClientEvent:Connect(function(player, ProductName)
	if player.Name == game.Players.LocalPlayer.Name then
		print("Recived.")
		text.Text = tostring(ProductName)
        	text:TweenPosition(
			UDim2.new(0.5, 0,0.5, 0), 			
			Enum.EasingDirection.InOut, 
			Enum.EasingStyle.Quad, 
			1, 
			false
		)
    		wait(5)
    		text:TweenPosition(
			UDim2.new(.5, 0,-0.2, 0), 
			Enum.EasingDirection.InOut, 
			Enum.EasingStyle.Quad, 
			1, 
			false
		)
	end
end)

1 comment

0

That didn't work. It didn't print Recieved

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