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

Ball throwing script works in local, but not in server?

Hi, I'm trying to get servers but they're eluding me.

Right now I'm trying to prototype a basketball tool -- it can be held and thrown by the player. It works fine in local testing, but in network testing it breaks -- the ball jumps down a couple units below the player throwing it and then drifts backwards slightly? can't tell what the problem is.

My method of implementation is to have a localscript and serverscript in the ball. the localScript calls a server event that unparents the ball and sets its velocity.

In the localscript:

script.Parent.Activated:Connect(function()
	ShootScript.ShootEvent:FireServer()
end)

in the serverscript:


local character = Tool.Parent;
local humanoid = character.Humanoid
if humanoid == nil then
	print("Humanoid not found")
	return 
end
local lookAt = (humanoid.TargetPoint - character.Head.Position).unit

local vPlayer = game.Players:playerFromCharacter(character)
local spawnPos = character.PrimaryPart.Position + (lookAt * 5)
wait()
Tool.Parent = game.Workspace
Tool.Handle.Position = spawnPos
Tool.Handle.Velocity = (lookAt * script.Parent.PowerValue.Value)+Vector3.new(0,50,0)

Thanks a lot

2 comments

0

In line 9, it’s GetPlayerFromCharacter, not playerFromCharacter.

0

Deprecated bvut not the error

1 answer

Is there a need to keep the Serverscript inside the tool? Maybe try to put the serverscript in ServerScriptService and use the OnServerEvent? For example:

Localscript:

script.Parent.Activated:Connect(function()
    ShootScript.ShootEvent:FireServer(Tool) --Adding tool as a parameter
end)

Serverscript:

--Of course, directory for the remote event will be different
ShootEvent.OnServerScript:Connect(function(player, Tool)
	local character = player.Character;
	if character then
		local humanoid = character:FindFirstChild("Humanoid");
	end
	--Keep everything else the same
end)

Try that, and see if it hopefully works

1 comment

0

I was hoping it would -- but it seems that anything I put into serverscriptstservice gets destroyed -- i tried moving the server script into the game workspace and the same behavior occurred -- I also tried separating the event from the script, leaving the script in the SSService

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