I need a bit of help please

i have a issue, my remote event isnt firing, i am trying to make if a player types something a trash from the ground will appear(pls no hate me new) anyways here script:

Local script:
local rs = game:GetService(“ReplicatedStorage”)
local specificmsg = “trash appear!”
local Player = game:GetService(“Players”)
local TrashAppear = rs:WaitForChild(“TrashAppear”)

game.Players.Chatted:Connect(function(msg)
if msg:lower() == specificmsg then
TrashAppear:FireServer()
end

end)

serverscript:

local rs = game:GetService(“ReplicatedStorage”)
local TrashAppear = rs:WaitForChild(“TrashAppear”)
local tweenservice = game:GetService(“TweenService”)
local trash = game.Workspace.TrashBin

TrashAppear.OnServerEvent:Connect(function(player, trash)
local tweeninfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local goal = {CFrame = trash.CFrame + Vector3.new(0, 200, 0)}


local tween = tweenservice:Create(trash, tweeninfo, goal)
tween:Play()

end)

game.Players.Chatted will not work, your code is saying the Players service has a .Chatted event. It doesn’t.

Since this is being ran on a LocalScript, they can reference the LocalPlayer. I would use that.

-- MODIFIED
local rs = game:GetService("ReplicatedStorage")
local specificmsg = "trash appear!"
local Player = game:GetService("Players")
local TrashAppear = rs:WaitForChild("TrashAppear")

local Player = game.Players.LocalPlayer

Player.Chatted:Connect(function(msg: string)
	if string.lower(msg) == specificmsg then
		TrashAppear:FireServer()
	end
end)

Also please note that you should NOT be running tweens on the server. That isn’t good. Tweens should always be executed on the CLIENT.

2 Likes

About the tweens, I wouldn’t really agree to that. Why should they be executed only on client? A tween which moves a part wouldn’t really spend much resources; moving the part in the Workspace for every client manually would cause much more work and new players wouldn’t see the part at all.

1 Like

Yes, it would cause much more work, but on the clients end. I feel it is better computationally for clients to execute tweens instead of the server. It is already handling a myriad of computations than clients, and to not run tweens on clients would be a waste of potential resources.

For new players, I would use a sort of Update() function when they join.

1 Like

I think you are being too cautious about it. There is no real potential threat from a second long Tween replicated by Server. Some thousand-lined scripts increase memory consumption only by 5-10 megabytes. Think of that being compared to Tweens. Server’s task is to change the Property of the Instance, which is probably no more than few bytes, the way it is displayed in the Workspace (if it even is) is already client’s problem (correct me if I am wrong)
More than that, ROBLOX servers memory is capped at 6.4GB, thats much more than average mobile user’s RAM.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.