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

I can not send a value to the server and use it properly... Why?

I have made a voting system for a story type game. The player goes down the road and has to choose which path they take. The good thing about this system is if I get it to work I can just keep calling it in the server with different values for different votes. After they vote the value is supposed to be sent to the server for the NPC to say which direction they are going.

Server (only relevant code) :

local rStorage = game:GetService("ReplicatedStorage")
local rEvents = rStorage:WaitForChild("Events")
local votewinner = ""
local NPCs = workspace.NPCs

rEvents.DialogueVisible:FireAllClients(false)
rEvents.VoteEvent:FireAllClients("Which way should we go?", 2, 10, "Left", "Right")
wait(10)
rEvents.VoteResults.OnServerEvent:Connect(function(player, winner)
	if winner == 1 then
		votewinner = "left"
	end
	if winner == 2 then
		votewinner = "right"
	end
	rEvents.DialogueVisible:FireAllClients(true)
	rEvents.Dialogue:FireAllClients(NPCs.John, "Looks like we are going ".. votewinner.. ".")
end)

Local (only relevant code):

	rValues.Vote2.Changed:Connect(function()
		clone2.Counter.TextLabel.Text = rValues.Vote2.Value
		print(rValues.Vote2.Value)
	end)
	wait(votetime)
	if rValues.Vote1.Value > rValues.Vote2.Value then
		winner = clone1.Name
		print(winner)
	end	
	if rValues.Vote2.Value > rValues.Vote1.Value then
		winner = clone2.Name
		print(winner)
	end
	if rValues.Vote1.Value == rValues.Vote2.Value then
		local randomOptions = {clone1.Name, clone2.Name}
		local RandomResult = math.random(#randomOptions)
		for i=1, 1 do
			winner = winner..randomOptions[RandomResult]
		end
		print(winner)
	end
	rEvents.VoteResults:FireServer(player, winner)
	script.Parent.Visible = false
	wait()
	removeChoices()

1 comment

0

Isn't everything below line 4 suppose to be inside your .Changed:connect

1 answer

You don't need to send the player. The player parameter is automatically passed to the server. So change your script to this:

Local Script

rEvents.VoteResults:FireServer(winner)

The reason why is because it will think you have 3 parameters, which is the player, player again, and then the winner.

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