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

Why doesn't my remote event work properly?

I don't know why my remote event script isn't working well. It won't work, it won't have an error, and it will just remove the hats and hairs

local script

done:FireServer(plr) end

script

done.OnServerEvent:connect(function(plr) local char = plr.Character:GetChildren() local per = game.Workspace["avatar"..plr.Name].person:GetChildren() for i, v in pairs (char) do if v:isA("Accountrement") then v:Destroy()

	end
end

for i, v in pairs (per) do
	if v:isA("Accountrment") then v.Parent = plr.Character
	 plr.Character.Pants.PantsTemplate = v.Pants.PantsTemplate
	plr.Character.Shirt.ShirtTemplate = v.Shirt.ShirtTemplate
	end
end

end)

3 comments

0

Can you put all of the code between the ~~~ lines

0

......?

0

aren't you able to read it?

1 answer

✓ Accepted answer

You made a mistake in firing the event. When you fire an event TO the server, you're not supposed to add the player as a variable because the server already has the player as a variable. Secondly, you're not supposed to add "end" when firing events.

Here's some example code:

LocalScript

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Event:FireServer()

ServerScript

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(plr)
	--Code
end)

Just a tip: You should always put ALL your code into a code block so it will be easier for people to read your code. To do that, highlight ALL the code and press the blue Lua button. It will add "~" around the code.

EDIT:

Here's a RemoteEvent that tells the server to request new clothing for the character.

LocalScript

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Event:FireServer()

ServerScript

local Event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

Event.OnServerEvent:Connect(function(plr)
	if plr.Character then --Checks for the character.
		for i,v in pairs(plr.Character:GetChildren()) do
			if v:IsA("Accoutrement") or v:IsA("ShirtTemplate") or v:IsA("PantsTemplate") then
				v:Destroy() --Removes all clothing.
			end
		end
		
		--Make a folder in ServerStorage with new Accessories and Shirt / Pants.
		for i,v in pairs(game.ServerStorage.Folder:GetChildren()) do
			v:Clone().Parent = plr.Character --Clones new clothing to the character.
		end
	end
end)

7 comments

0

I forgot to inform you that I put an end) since it's inside of a mousebutton1down function but it still doesn't work :/

0

What are you trying to do with your script? Remove the players current clothing and replace it with new ones?

0

pretty much but the remote event gave up on me XD

0

I used two loops and the remote event doesn't do anything...

0

I'll edit the question and see if it works for you

0

THANK YOU SO MUCH :D

0

No problem!

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