--Here's the local script which is in a gui button

player = game.Players.LocalPlayer
button = script.Parent

clicksleft = 5
button.MouseButton1Down:Connect(function()
	if clicksleft == 5 then
		clicksleft = clicksleft - 1
		button.Events.melee:FireServer()
		script.Parent.Text = "Click for a random staff"		
		print (clicksleft .. script.Parent.Text)
	end
end)
--This is the server script which is inside the gui button also

Melee = {}
for i,v in pairs (weapons.Melee:GetChildren()) do
	table.insert(Melee, v.Name)
end 

melee.OnServerEvent:Connect(function(plr)
	print("test")
	math.randomseed(tick())
	local chosen = math.random(1, #Melee)
	for i,v in pairs(weapons.Melee:GetChildren()) do
		if v.Name == (Melee[chosen]) then
			local clone = v:Clone()
			clone.Parent = plr.Backpack
		else
		end
	end
end)

This all works perfectly in studio, but when I play the game, it doesn't work. It prints the stuff from the local script but doesn't even print "test" from the server script.

5 comments

0

"This is the server script which is inside the gui button also." RemoteEvents should be located in the server, not the client.

0

I tried it in serverscriptservice but that didn't work either. It said that it cannot find the script.

0

Okay, it worked in workspace. Thanks.

0

Put the remotes in ReplicatedStorage and the script in server script service

0

They work fine inside of the script.