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

Sending a remote event from the server to the client not working?

Im trying to get a click detector to fire on the server because that seems like the only way the click detector will work. But when i test it nothing happens

i dont get any errors or anything in the output besides the "re works"

--Script

local button = script.Parent
local click = script.Parent:WaitForChild("Click")
local RE = script.Parent:WaitForChild("ClickEvent")

click.MouseClick:Connect(function(player)
	RE:FireClient(player)
	if RE then
		print("re works")
	end
end)

--Local Script

local button = script.Parent
local click = script.Parent:WaitForChild("Click")

local Remote = script.Parent:WaitForChild("ClickEvent")

local TS = game:GetService("TweenService")

local TI = TweenInfo.new(
	1,
	Enum.EasingStyle.Quad,
	Enum.EasingDirection.InOut,
	0,
	true,
	0
)

local buttonprop = {
	Color = Color3.fromRGB(255,255,255)
}

local Tween = TS:Create(button,TI,buttonprop)

local function buttonPressed(player)
	print("Test")
end

Remote.OnClientEvent:Connect(buttonPressed)

1 answer

✓ Accepted answer

So the issue I see is that a remote event has to be inside the ReplicatedStorage and that the local script is not inside the player's scripts

Try something like this:

--Script (inside of Button)

local RepStore = game.ReplicatedStorage
local button = script.Parent
local click = script.Parent:WaitForChild("Click")
local RE = RepStore:WaitForChild("ClickEvent")

click.MouseClick:Connect(function(player)
    RE:FireClient(player, button)
end)

-- Local Script (Inside StarterPlayer.StarterPlayerScripts)

local RepStore = game.ReplicatedStorage
local RE = RepStore:WaitForChild("ClickEvent")
local TS = game:GetService("TweenService")

local TI = TweenInfo.new(
    1,
    Enum.EasingStyle.Quad,
    Enum.EasingDirection.InOut,
    0,
    true,
    0
)

local buttonprop = {
    Color = Color3.fromRGB(255,255,255)
}


local function buttonPressed(player, button)
	print("Test")
	local Tween = TS:Create(button,TI,buttonprop)
	Tween:Play()
end

Remote.OnClientEvent:Connect(buttonPressed)

Let me know if there's any issues :)

Learn more about Remote Events here

Learn More about TweenService here

2 comments

0

im getting an error in the output saying "TweenService:Create failed because Instance is null"

0

nvm got it fixed

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