Edit: This got solved in the comments, edited the title to include grammar mistakes so I'm within the character limit.

Hi!

I'm trying to get a player to drop a bomb when pressing space. I'm currently handling this with the FireServer function and putting in the player's userid in as argument.

During this the argument seems to have become an instance instead to an integer. Since I require an integer instead of an Instance, the script breaks and cannot continue.

The localscript that fires the event when pressing space:

local input = game:GetService("UserInputService")

while not input.KeyboardEnabled do
	wait()
end

local keyboard = input.KeyboardEnabled

while true do
	
	if keyboard and input:IsKeyDown(32) then --Check if space is pressed
		
		id = game.Players.LocalPlayer.UserId
		
		game.Workspace.Bombhandle:FireServer(id)
		print(id) --When starting a local server for testing this returns -1
		wait(0.3) --Cooldown
		
	end
	
	wait()
	
end

And the server sided script:

--Handles the server side of placing a bomb when receiving a fire event from the remote event.

local event = game.Workspace.Bombhandle

event.OnServerEvent:connect(function(userid)
	
	local chr = game.Players:GetPlayerByUserId(userid).Character --This line returns the error "Unable to cast Instance to int"
	
	--TODO check if the player has the amount of bombs required
	
	
	--Get the variables we need to have the bomb in proper
	local Power = chr.Stats.Pwr.Value
	local Range = chr.Stats.Rng.Value
	local Pos = chr.Torso.Position
	
	--Create the bomb, but don't place it in yet.
	local bomb = game.ReplicatedStorage.BombBall:Clone()
	
	--Set up the bomb values.
	bomb.Pwr.Value = Power
	bomb.Rng.Value = Range
	bomb.Position = Pos
	
	--And now put it in the game
	bomb.Parent = game.Workspace
	
end)

3 comments

0

Maybe the event returns the player or character?

0

@Wutras Oh, you're correct! Thank you! :)

0

No problem. :)