When I run the script in Roblox studio it works but when I run it in game it dosen’t work. How would I fix this problem?
Heres the script I used:
game.Players.PlayerAdded:Connect(function(player)
local AddGolf = Instance.new("Part",workspace.GolfFolder)
local GolfCam = Instance.new("Part", workspace.CamFolder)
local GolfPlayer = Instance.new("StringValue",AddGolf)
local GolfPos = Instance.new("IntValue", AddGolf)
AddGolf.Shape = "Ball"
AddGolf.Size = Vector3.new(1,1,1)
AddGolf.Position = Vector3.new(0, 5, 0)
AddGolf.Name = player.name
AddGolf.Anchored = false
GolfCam.Name = player.name
GolfCam.Anchored = true
GolfCam.Transparency = 1
GolfCam.CanCollide = false
GolfPlayer.Value = player.name
GolfPlayer.Name = "Name"
GolfPos.Name = "Pos"
end)
local RemoteEvent = game.ReplicatedStorage:WaitForChild("FireEvent")
game.ReplicatedStorage.FireEvent.OnServerEvent:Connect(function(player, mouse)
local plr = player.name
workspace.GolfFolder[player.name]:SetNetworkOwner(player)
workspace.GolfFolder[plr].CFrame = CFrame.new(workspace.GolfFolder[plr].Position, mouse)
workspace.GolfFolder[plr].Velocity = workspace.GolfFolder[plr].CFrame.lookVector * 50
end)
Hey there. Do you have any errors when doing it? Can you print the following after setting it to see if it is infact still set to the server?
print(workspace.GolfFolder[player.Name]:GetNetworkOwner())
Additionally, I highly suggest using :FindFirstChild(player.Name) and then proceeding.
Hi, I get no errors and now it prints the player’s name. I also changed the script to use :FindFirstChild as you suggested.
If it printed the player name, that means it is set to them!
So it is working as it should?
BanTech
(BanTech)
March 25, 2020, 9:07pm
#6
What is it that makes you believe it didn’t work? You should describe the intended result versus the one you got.
It’s hard to tell who the network owner is without printing the owner. If the owner matches the thing you set it to, then it’s worked.
Also a top tip for future posts, use three backticks ``` at the start and end of your code to maintain your indentation and make it so much easier to read for people who want to help.
game.Players.PlayerAdded:Connect(function(Player)
local AddGolf = Instance.new("Part") do
AddGolf.Shape = "Ball"
AddGolf.Size = Vector3.new(1,1,1)
AddGolf.Position = Vector3.new(0, 5, 0)
AddGolf.Name = Player.name
AddGolf.Anchored = false
AddGolf.Parent = workspace.GolfFolder
end
local GolfCam = Instance.new("Part") do
GolfCam.Name = Player.name
GolfCam.Anchored = true
GolfCam.Transparency = 1
GolfCam.CanCollide = false
GolfCam.Parent = workspace.CamFolder
end
local GolfPlayer = Instance.new("StringValue") do
GolfPlayer.Value = Player.name
GolfPlayer.Name = "Name"
GolfPlayer.Parent = AddGolf
end
local GolfPos = Instance.new("IntValue", AddGolf) do
GolfPos.Name = "Pos"
GolfPos.Parent = AddGolf
end
end)
local RemoteEvent = game.ReplicatedStorage:WaitForChild("FireEvent")
RemoteEvent.OnServerEvent:Connect(function(Player, Mouse)
local PlayerName = Player.name
workspace.GolfFolder[PlayerName]:SetNetworkOwner(Player)
workspace.GolfFolder[Player].CFrame = CFrame.new(workspace.GolfFolder[Player].Position, Mouse)
workspace.GolfFolder[Player].Velocity = workspace.GolfFolder[Player].CFrame.lookVector * 50
end)
An improvement you could make in the future, is to set the parent of objects last ;
I’ve discovered a pretty bad performance issue in one of top games that has to do with Instance.new and wanted to write about this, since this is not obvious unless you know the system inside out.
Tthere are several ways to create a ROBLOX object in Lua:
local obj = Instance.new(‘type’); fill obj fields
local obj = Instance.new(‘type’, parent); fill obj fields
local obj = util.Create(‘type’, { field1 = value1, … })
If you care at all about performance, please only use the first option - I wi…
The ball lags when I shoot it but not in Roblox studio thats why I thought it didn’t work.