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

Why doesn't this RemoteEvent fire in game?

I'm attempting to make a team change GUI that clones the team into the teams if it is not already there.

It works fine in Studio although once in game, it doesn't work whatsoever.

This has to be done using FilteringEnabled due to the buyers request.

LocalScript:

local team=game.ReplicatedStorage.Teams[script.Parent.Text]
local player=script.Parent.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:connect(function()
	if player:IsInGroup(3159287) then
		if game.Teams:FindFirstChild(script.Parent.Text)==nil then
		game.ReplicatedStorage.MainframeEvents.CloneCC:FireServer(player)
		end
	end
end)

--3063035

Script:

local team=game.ReplicatedStorage.Teams:FindFirstChild(script.Parent.Text)

game.ReplicatedStorage.MainframeEvents.CloneCC.OnServerEvent:connect(function(player)
	print("Event Fired")
	team:Clone().Parent=game.Teams
	script.Parent.Parent.Parent.Parent.Parent.Parent.Team=game.Teams[script.Parent.Text]
	player:LoadCharacter()
end)

1 answer

First of all, you should ALWAYS do checks like IsInGroup() on the server, because they can easily be spoofed by exploiters.

Second of all, don't store Team instances in ReplicatedStorage. Create them on the fly if necessary.

Server script:

local teamsList = {
	SomeTeam = BrickColor.new("Really red"),
	OtherTeam = BrickColor.new("Teal"),
}

local mfEvents = game:GetService("ReplicatedStorage").MainframeEvents

local teamEvent = mfEvents.CloneCC
teamEvent.OnServerEvent:Connect(function(plr, team)
	if not plr:IsInGroup(3159287) then
		return --abort if they aren't in the group
	end
	if not game:GetService("Teams"):FindFirstChild(team) then
		local teamColor =  teamsList[team]
		if teamColor then
			local newTeam = Instance.new("Team", game:GetService("Teams"))
			newTeam.Name = team
			newTeam.TeamColor = teamColor
		else
			return
		end
	end
	plr.Team = game:GetService("Teams"):FindFirstChild(team)
end)

Local script:

local plr = game:GetService("Players").LocalPlayer --this is how you get the current player with localscript
local mfEvents = game:GetService("ReplicatedStorage").MainframeEvents

local teamEvent = mfEvents.CloneCC

script.Parent.MouseButton1Click:Connect(function()
	teamEvent:FireServer(script.Parent.Text)
end)

1 comment

0

Tried it, still wont work in play mode. Any suggestions?

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