Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Workspace value isnt being detected by script?

Asked by 2 years ago
Edited 2 years ago

I'm working on a tool which gives you a stand after used. When a player joins, a folder is made in the workspace which has a string value inside. This string value contains the Stand's Name, ("THEWORLD", "STARPLATINUM", etc.) The string value and everything works fine. But the problem is that the arrow isn't detecting the value. I tried changing it with a local script. And it worked the first time, but when I used a server script with an event to change it, it all broke. Can anyone help me out?

Local Script:

local player = game:GetService("Players").LocalPlayer
local char = player.Character
local hum = char:WaitForChild("Humanoid")
local stand = workspace:FindFirstChild(player.Name.." StandChecker")

local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:FindFirstChild("StandArrow")

local debris = game:GetService("Debris")

script.Parent.Activated:Connect(function()
    print("Activated! Checking for StandChecker")
    if stand then

        print("Found StandChecker! Checking Stand.")
        if stand.Stand.Value == "None" then

            print("No Stand! Giving Stand now...")

            --// Playing The Animation
            hum.JumpPower = 0
            hum.WalkSpeed = 0
            local anim = hum:LoadAnimation(script.Parent.Stab)

            anim:Play()
            wait(.3)
            --// Making Effects
            workspace:FindFirstChild("Sounds"):FindFirstChild("Arrow"):Play()

            wait(1.05)
            --// Giving the player a stand
            local standGiven = "THEWORLD"
            event:FireServer(standGiven, player.Name)

            hum.JumpPower = 40
            hum.WalkSpeed = 14

            script.Parent:Destroy()
        else

            print("Woops! "..player.Name.." already has a stand!")
        end
    else

        warn("No StandChecker :(")
    end

    print("Finished!")
end)

Server script:

local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage:FindFirstChild("StandArrow")

event.OnServerEvent:Connect(function(standGiven, player)
    local stand = workspace:FindFirstChild(player.." StandChecker")
    if stand then
        print("found stand B)")
        local standValue = stand.Stand.Value
        if standValue then
            print("B/ stand to give is "..standGiven)
            print("B/ current Stand is "..standValue)

            standValue = standGiven
        else
            print("wheres the stand value >B(")
        end
    else
        print("ayo no stand >B(")
    end

end)

If anyone can help me out with this that would be greatly appreciated. Thanks!

2 answers

Log in to vote
1
Answered by
TGazza 1336 Moderation Voter
2 years ago

You have the server event parameters wrong way round. FireServer event automatically gives the player that invoked or called the server event automatically, so doing the following is unnecessary:

Local script:

-- Code
            wait(1.05)
            --// Giving the player a stand
            local standGiven = "THEWORLD"
            event:FireServer(standGiven, player.Name) -- this is unnecessary! 

            hum.JumpPower = 40
            hum.WalkSpeed = 14
-- Code

Change the event line in your Local script from this:

            event:FireServer(standGiven, player.Name) 

To this:

            event:FireServer(standGiven) 

And in your server side script, Change the following line:

event.OnServerEvent:Connect(function(standGiven, player)

To this:

event.OnServerEvent:Connect(function(playerChar,standGiven)
local player = playerChar.Name -- Since you're using the name in your code just add this here before anything else!

Hope this helps! :)

0
Trying this right now, just one question. How is the server script getting the character from the event when it's not passing through? Spookdoggz 42 — 2y
0
Ohhh, sorry, I just realized what was on the top of your answer Spookdoggz 42 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

I suggest instead of making it a value in workspace, make it a value in your script. Here's an example -

local standValue = ""

if standValue then
standValue = standGiven
print(standValue
end

If this doesn't work, try making a table -

local stands = {"The World", "Star Platinum", "Something Cool!"}

local randomStand = math.random(1, #stands)
standSelected = stands[randomStand]

This would randomly select a stand from a table without the use of a StringValue.

0
I would do this, however I have a bunch of other scripts that require the workspace string. I'm not sure if that's an issue though. Spookdoggz 42 — 2y
0
I re-tested this and it's just not detecting the value. That may be the problem here. Spookdoggz 42 — 2y
0
You could try to insert the table to a module script and require that module from your other scripts. BirthWormSaiiy 48 — 2y

Answer this question