Hello! I’m trying to get the server-side to work but it doesn’t work, I don’t understand what I connected or did I do wrong, could someone give me a hand, please.
localscript:
local chooseElectricGuitar = script.Parent.Frame:WaitForChild("On/Off")
local isOn = false
local debounce = false
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventAddGuitar = replicatedStorage:WaitForChild("remoteEventAddGuitar")
local remoteEventRemoveGuitar = replicatedStorage:WaitForChild("remoteEventRemoveGuitar")
chooseElectricGuitar.MouseButton1Click:Connect(function()
if not debounce then
debounce = true
if isOn then
-- Turn off the guitar
print("Turning off...")
-- Fire the remote event to remove the guitar
print("Firing remote event to remove the guitar")
remoteEventRemoveGuitar:FireServer()
else
-- Turn on the guitar
print("Turning on...")
-- Fire the remote event to add the guitar
print("Firing remote event to add the guitar")
remoteEventAddGuitar:FireServer()
end
chooseElectricGuitar.Text = isOn and "Off" or "On"
isOn = not isOn
task.wait(0.5)
debounce = false
end
end)
server script:
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEventAddGuitar = replicatedStorage:WaitForChild("remoteEventAddGuitar")
local remoteEventRemoveGuitar = replicatedStorage:WaitForChild("remoteEventRemoveGuitar")
-- Function to add the guitar model
local function onAddGuitar(player)
print("Function onAddGuitar started for player:", player.Name)
local character = player.Character or player.CharacterAdded:Wait()
print("Character acquired:", character)
local getUpperTorso = character:WaitForChild("UpperTorso")
print("UpperTorso found:", getUpperTorso)
local guitarCloned = replicatedStorage:WaitForChild("TestingGuitar"):Clone()
print("Guitar clone created:", guitarCloned)
guitarCloned.Parent = getUpperTorso
print("Guitar parented to UpperTorso")
local guitarParented = getUpperTorso:FindFirstChild("TestingGuitar")
print("Guitar found in UpperTorso:", guitarParented)
if guitarParented then
print("Anchoring guitar's Handle")
guitarParented.Handle.Anchored = true
else
print("Guitar cloning failed!")
end
print("Function onAddGuitar finished")
end
-- Function to remove the guitar model
local function onRemoveGuitar(player)
local character = player.Character or player.CharacterAdded:Wait()
-- Find all model instances with the correct name
for _, child in pairs(character:GetChildren()) do
if child.Name == "TestingGuitar" and child:IsA("Model") then
child:Destroy()
end
end
end
-- Connect events to functions
remoteEventAddGuitar.OnServerEvent:Connect(function(plr)
print("remote event add guitar activated from server")
onAddGuitar(plr)
end)
remoteEventRemoveGuitar.OnServerEvent:Connect(function(plr)
print("remote event remove guitar activated from server")
onRemoveGuitar(plr)
end)
-- Add print statements to confirm remote events are firing
remoteEventAddGuitar.OnServerEvent:Connect(function(plr)
print("remote event add guitar activated from server")
onAddGuitar(plr)
print("remote event add guitar finished")
end)
remoteEventRemoveGuitar.OnServerEvent:Connect(function(plr)
print("remote event remove guitar activated from server")
onRemoveGuitar(plr)
print("remote event remove guitar finished")
end)