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

ROBLOX Sword Model Functioning Only on the Client?

The ROBLOX sword players get when teleporting from the lobby to the arena in my game is not working, you can't swing and I cant see other player's swords. I think it might be because it's in a localScript, if so, how could I get around it?

Here's the code, if it helps:

local player = game.Players.LocalPlayer
local plrGui = player.PlayerGui
local intermissionTime = 30 -- in secs
local roundTime = 180 -- roundtime in secs
local timerMode = 1 -- 1 means intermission, 2 means round mode

local timerGui = plrGui.timerGUI

timerGui.Frame.modeLabel.Text = "Intermission" -- set it to intermission when the game
                                               -- starts so it isnt blank

while wait(1) do
	-- set timeLabel text to whatever the time left is
	if timerMode == 1 then
		roundTime = 180 -- set roundTime back to 180 since we're
		-- in intermission right now
		intermissionTime = intermissionTime - 1
		timerGui.Frame.timeLabel.Text = (tostring(intermissionTime))
		
		if intermissionTime < 1 then
			timerMode = 2
			timerGui.Frame.modeLabel.Text = "Match"
			
			-- give players swords
			local players = game:GetService("Players")
			
			for _,player in ipairs(game.Players:getChildren()) do
				local tool = game.ReplicatedStorage.ClassicSword:Clone()
				tool.Parent = player.Backpack
			end
			
			-- teleport all the players to the arena
			target = CFrame.new(13.8, 1.5, 42.3) --could be near a brick or in a new area
			for i, player in ipairs(game.Players:GetChildren()) do
				--Make sure the character exists and its HumanoidRootPart exists
				if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
					--add an offset of 5 for each character
					player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
				end
			end
		end
		
	elseif timerMode == 2 then
		intermissionTime = 30 -- set intermissionTime back to 30
		
		roundTime = roundTime - 1
		timerGui.Frame.timeLabel.Text = tostring(roundTime)
		
		if roundTime < 1 then
			timerMode = 1
			timerGui.Frame.modeLabel.Text = "Intermission"
			
			-- remove player swords
			local Players = game:GetService("Players")
			
			for _, Player in pairs(Players:GetPlayers()) do
				local Char = Player.Character or Player.CharactedAdded:Wait()
				local GearInPlayer = Player:FindFirstChild("Backpack")
				local GearInCharacter = Char:GetChildren()
				GearInPlayer:ClearAllChildren()
			
			
			-- teleport players to lobby
			target = CFrame.new(112.55, 102.989, 184.3) --could be near a brick or in a new area
			for i, player in ipairs(game.Players:GetChildren()) do
				--Make sure the character exists and its HumanoidRootPart exists
				if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
					--add an offset of 5 for each character
					player.Character.HumanoidRootPart.CFrame = target + Vector3.new(0, i * 5, 0)
				end
			end
		end
	end
end
end	
	

2 comments

0

well if we don't know the sword code we can't exactly fix the sword

0

A game-script should never be Local.

1 answer

✓ Accepted answer

The reason you arent able to see other peoples swords is because you are giving it to them in a local script, anything down in a local script will only be seen on the local players screen.. so to fix this on the lines where you are adding the swords to the players you want to do this instead:

-- give players swords
           Game.ReplicatedStorage.RemoteName:FireServer()

you then want to make a server script which will receive the event and add the swords to each player

game.ReplicatedStorage.RemoteName.OnServerEvent:Connect(function(plr)
	local tool = game.ReplicatedStorage.ClassicSword:Clone()
	tool.Parent = plr.Backpack
end)

hopefully this answered your question and worked for you, it was quite simple. although i do recommend that if your making a game script to start like rounds for matches or something for everyone do it by server script so anything it does is happening on the server side and not just the clients side.

2 comments

1

There are several issues with the asker's code. Although your answer is a valid solution, it's best to not ignore the blatant issue with using a LocalScript to house entire game-logic.

0

Yes that is true and ive mentioned at the end of my answer to use Server scripts for these types of things, but that is up to the asker.

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