Gets player.playername instead of getting player object in workspace

  1. What do you want to achieve? i want to make a soccer ball locally get kicked on the client side and not the server side

  2. What is the issue? i have a script that sees when the ball is touched and it checks if its a character and then i put it into a table to tell a other script the object in workspace so it does the rest of the stuff and makes it hit locally but instead it says Player.Exotic_stuffing so im guessing its not getting the player in workspace but it is getting player in workspace

  3. What solutions have you tried so far? i edited the script for over 3 hours and nothing worked, i edited differnet stuff and it still doesnt work, and im bummed out of it.

local script (in startercharcaterscripts)


local Services = {
	Players = game:GetService("Players"),
	Debris = game:GetService("Debris"),
	rep = game:GetService("ReplicatedStorage")

}
local Settings = {
	Kick_Cooldown = 1,
	Kick_Force = 35
}
local Ball = game.Workspace.SoccerBall
local KickSound = Ball:WaitForChild("Kick")
local IgnoreTable = {}

Ball.Touched:Connect(function(Part)
	local Character = Part.Parent
	if not Character then
		return
	end
	
local stuff = {
	
		thing = Character
	}
	game.ReplicatedStorage.RemoteEvents.a:FireServer(stuff)
end)

main script (inside ball)

game.ReplicatedStorage.RemoteEvents.a.OnServerEvent:Connect(function(stuff)


local Ball = script.Parent

local Services = {
	Players = game:GetService("Players"),
	Debris = game:GetService("Debris")

}
local Settings = {
	Kick_Cooldown = 1,
	Kick_Force = 35
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
	local IgnoreTable = {}
	
	local Character = stuff
	local Player = Services.Players:GetPlayerFromCharacter(Character)
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local Root = Character:FindFirstChild("HumanoidRootPart")
	if not Player or not Humanoid or Humanoid.Health <= 0 or not Root or table.find(IgnoreTable, Player) then
		return
	end

	local Direction = CFrame.lookAt(Root.HumanoidRootPart.Position, Ball.Position).LookVector
	if Direction.Magnitude < 0.001 then
	local Velocity = Instance.new("BodyVelocity")
	Velocity.Parent = Ball
	Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
	Velocity.Velocity = (Direction.Unit * Settings.Kick_Force) + Vector3.new(0, Settings.Kick_Force /1.05, 0)
	Services.Debris:AddItem(Velocity, 0.2)
	KickSound:Play()
	end
end)

help will be appreciated!!!

the player who fired is always the first variable when firing the server so you should use

game.ReplicatedStorage.RemoteEvents.a.OnServerEvent:Connect(function(Player, stuff) -- this is not the player who kicked but the player who fired the remote

from what i see you are going to have alot of clients firing the remote if they are all watching touched event on a server created soccer ball

This should probably be in a server script that way there is only one connection

Also i have added how you could get the player who kicked the ball above

image

i edited the code you gave me and added my changes and it says the same now?

line of code in 35:

local Direction = CFrame.lookAt(Player.Position, Ball.Position).LookVector

1 Like

Try Player.Character.PrimaryPart.Position.

Try this too:

game.ReplicatedStorage.RemoteEvents.a.OnServerEvent:Connect(function(Player, stuff)


local Ball = script.Parent

local Services = {
	Players = game:GetService("Players"),
	Debris = game:GetService("Debris")

}
local Settings = {
	Kick_Cooldown = 1,
	Kick_Force = 35
}
local Ball = script.Parent
local KickSound = Ball:WaitForChild("Kick")
	local IgnoreTable = {}
	
	local Character = stuff[1]
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	local Root = Character:FindFirstChild("HumanoidRootPart")
	if not Humanoid or Humanoid.Health <= 0 or not Root or table.find(IgnoreTable, Player) then
		return
	end

	local Direction = CFrame.lookAt(Root.Position, Ball.Position).LookVector
	if Direction.Magnitude < 0.001 then
	local Velocity = Instance.new("BodyVelocity")
	Velocity.Parent = Ball
	Velocity.MaxForce = Vector3.new(1, 1, 1) * math.huge
	Velocity.Velocity = (Direction.Unit * Settings.Kick_Force) + Vector3.new(0, Settings.Kick_Force /1.05, 0)
	Services.Debris:AddItem(Velocity, 0.2)
	KickSound:Play()
	end
end)

To get the player character from a player object you would need to get

.Character (ex : 123456789_players.Character)

To get the character from the username you would do

local Player = game.Players:FindFirstChild(“123456789_players”)
if Player then
local Character = player.Character
end

it works really good but its server sided

So? What’s wring with being server sided? That’s even better most of the time.

what you can do is do the connection to the ball server side when touched then get direction or locations to move it to then fire remote to the clients to move or do what you want to the ball this is also used to show bullets, snowballs, and other objects that move without server running the physics. but in your case its probably fine for the ball to be run by the server just make sure to set networkownership to the server else the closest client will pickup owner and cause the ball to twitch or lag as it moves